# Example of fatality rate and beer taxes open "/Volumes/FLASH DRIVE/EAplicada/Week11_2016/fatality.gdt" MR = 10000*mrall # 1982 smpl year==1982 --restrict ols MR const beertax --robust smpl --full # 1988 smpl year == 1988 --restrict ols MR const beertax --robust smpl --full # pooled cs smpl year == 1988 || year == 1982 --restrict d88 = year==1988 ols MR const beertax d88 --robust smpl --full # first difference smpl year == 1988 || year == 1982 --restrict #generate first differences (bw 1988 and 1982) diff beertax MR #or using lag operator genr Dbt=beertax-beertax(-1) genr Dvf=MR-MR(-1) smpl --full smpl year==1988 --restrict ols d_MR const d_beertax --robust ols Dvf const Dbt --robust smpl --full ############################ # deviations from the mean or within estimator: smpl year == 1988 || year == 1982 --restrict #declare a panel setobs state year --panel-vars panel MR const beertax --fixed-effects --robust --time-dummies panel MR const beertax d88 --fixed-effects --robust smpl --full ########################### # including individual dummies # make sure that state is discrete for gretl: setinfo state --discrete smpl year == 1988 || year == 1982 --restrict ols MR const beertax dummify(state) dummify(year) --robust smpl --full # using panel commands for dummies setobs state year --panel-vars genr unitdum genr timedum smpl year == 1988 || year == 1982 --restrict ols MR const beertax du_* dt_* --robust smpl --full # within estimator with unemployment rate: smpl year == 1988 || year == 1982 --restrict #declare a panel setobs state year --panel-vars panel MR const beertax unrate --fixed-effects --robust --time-dummies smpl --full # within estimator with additional variables: smpl year == 1988 || year == 1982 --restrict #declare a panel setobs state year --panel-vars panel MR const beertax unrate pop --fixed-effects --robust --time-dummies smpl --full ############################################################# #Using 3 years: 1982, 1985, 1988 #generate first differences smpl year == 1982 || year == 1985 || year == 1988 --restrict diff beertax MR smpl --full # FD smpl year == 1985 || year == 1988 --restrict ols d_MR const d_beertax --robust smpl --full # within estimator smpl year == 1982 || year == 1985 || year == 1988 --restrict setobs state year --panel-vars panel MR const beertax --fixed-effects --robust --time-dummies smpl --full # including fixed effects setinfo state --discrete smpl year == 1982 || year == 1985 || year == 1988 --restrict ols MR const beertax dummify(state) dummify(year) --robust smpl --full ################################################################## #guns clear open "/Volumes/FLASH DRIVE/EAplicada/Week11_2016/Guns.gdt" # Generate variables lvio = ln(vio) ols lvio const shall --robust ols lvio const shall incarc_rate density avginc pop --robust setinfo stateid --discrete ols lvio const shall incarc_rate density avginc pop dummify(year) dummify(stateid) --robust omit Dyear* --quiet # within estimator (same as previous) setobs stateid year --panel-vars panel lvio const shall incarc_rate density avginc pop --fixed-effects --robust --time-dummies ################################################################## #sindicatos clear open "/Volumes/FLASH DRIVE/EAplicada/Week11_2016/wagepan_PSpanel.gdt" genr expe_sq=exper*exper freq year #MODELO LWAGE=THETA_t + Beta Xit +PI*Zi + a_i+u_it #(a) Interpretation theta and a_i #(b) sign beta_union #(c) OLS pool cross sections ols lwage const dummify(year) union exper expe_sq married black hisp educ --robust #(d) P Diferencias diff lwage const union exper expe_sq married black hisp educ loop foreach i 1981 1982 1983 1984 1985 1986 1987 genr du_y_$i=year=$i endloop diff lwage const union exper expe_sq married black hisp educ du_y_* smpl year>1980 --restrict ols d_lwage d_du_y_* d_union d_exper d_expe_sq d_married --robust ols d_lwage const du_y_1982 du_y_1983 du_y_1984 du_y_1985 du_y_1986 du_y_1987 d_union d_exper d_expe_sq d_married --robust u=$uhat #(e) Given the results corr(a_i,union) #(f) residual correlation ols u const u(-1) --robust #(g) (h) smpl --full setobs nr year --panel-vars panel lwage const union married --fixed-effects --robust --time-dummies #(i) panel lwage const union married --random-effects --robust --time-dummies