/*********** syntax 12.2 ***********/ /*************************** Applications of XI command ***************************/ sysuse auto,clear /***1.1:simple coding: comparing each group to a reference group***/ xi3:reg mpg g.rep78 xi:reg mpg i.rep78 /***1.2: forward difference coding:comparing each group to the next(adjacent) group***/ xi3:reg mpg a.rep78 /***1.3:backward difference coding:comparing each group to the prior adjacent group***/ xi3:reg mpg b.rep78 /***1.4:Helmert coding: comparing each group to the mean of the subsequent groups***/ xi3:reg mpg h.rep78 /***1.5:Reverse Helmert coding: comparing each group to the mean of the previous groups***/ xi3:reg mpg r.rep78 /***1.6:User defined coding***/ keep if rep78>1 tab rep78,sum(mpg) mean char rep78[user] (1 0 -1 0 \-.5 1 0 -.5 \ -.5 -.5 .5 .5) /***note:(1 0 -1 0):contrast of 1st and 3rd group; (-.5 1 0 -.5):contrast of 2nd group and the average of /// 1st and 4th group; (-.5 -.5 .5 .5):contrast of the first two and last two groups***/ xi3:reg mpg u.rep78 /*********************************** How to interpret log transformation? ***********************************/ /***Situation 1: exponential model,dependeant variable transformed***/ sysuse auto,clear hist mpg gen l_mpg=log(mpg) scatter mpg price scatter l_mpg price hist l_mpg reg l_mpg price /***Situation 2: log model: independent variable transformed***/ hist weight gen l_weight=log(weight) hist l_weight reg mpg foreign l_weight /***Situation 3: Power model, both dependent and independent variable transformed***/ reg l_mpg foreign l_weight /******************************************************* How to reg when your dependent variable is a proportion *******************************************************/ use http://cdph.fsu.edu/sya6933/proportion,clear sum meals twoway scatter meals parented,yline(0 1) reg meals parented predict mhat list in 1/10 sum mhat twoway scatter mhat parented,yline(0 1) glm meals parented, link(logit) family(binomial) robust nolog predict mhat2 sum mhat2 twoway scatter mhat2 parented,yline(0 1) /*********************************** How to apply weights in Stata? ***********************************/ /***pweights: sampling/probability weights***/ clear input race gpa 1 3.2 1 2.8 1 3.1 1 3.5 1 3.0 2 3.1 2 2.9 2 3.2 2 2.5 2 3.5 3 3.5 3 3.6 3 4 3 3.8 3 3.6 end list gen weight=0 replace weight=13.4 if race==1 replace weight=2.4 if race==2 replace weight=1 if race==3 list mean gpa mean gpa [pweight=weight] gen gpa1=gpa*weight gen N=sum(weight) gen sum_gpa=sum(gpa1) display 264.02/84