set more off clear capture log close cd "C:\Documents and Settings\jrgardne\Desktop\StataExample" log using StataExample.log , replace //set mem XXm /*----------------------------------------------------------------------------*/ use card.dta // You must download this first. It is Stata File 1 from // https://www.msu.edu/~ec/faculty/wooldridge/book2.htm /* Descriptive statistics ------------------------------------------------------------------------------*/ // summarize the data sum // summarize educ, exper, and wage in detail sum educ exper wage, detail // look at the levels of education tab educ // look at the levels of nearc2 tab nearc2 // look at educ by nearc2 tab educ nearc2 // look at the distribution of education hist educ graph export hist_educ.png, replace // replace overwrites the file if // we run the do file again // look at a scatterplot of wage and experience quietly scatter wage exper graph export wage_exper.png, replace // Notes: (1) For LaTeX, eps is a better output format. For Word, WMF/EMF is // better // (2) You can also use "graph save" to save the graph in the Stata // graph format /* Recoding the data ------------------------------------------------------------------------------*/ // make an indicator variable for living near either a 2 or 4 year college gen nearcol=. replace nearcol=1 if (nearc2==1 | nearc4==1) replace nearcol=0 if (nearc2==0 & nearc4==0) // Notes: it is good practice to initialize new variables to missing (".") // instead of zero, since if nearc2 or nearc4 are both missing, we want // nearcol to be missing and not zero // make an indicator variable for having a college degree of greater gen college=. replace college=0 if educ < 12 replace college=1 if (!missing(educ) & educ>= 12) // Note: We need the "!missing()" statement because Stata stores missing // values as large numbers. So if educ is missing, it is considered to be // greater than 12 drop lwage // generate the log wage gen lwage=log(wage) // Another useful function is exp(.) // use a loop to put education, experience and wages in deviations from means form foreach x in educ exper wage { egen `x'_mean=mean(`x') // create new variables containing the means of the variables // in the list -- this is a special kind of generation gen `x'_dm=`x'-`x'_mean } // summarize the new variables sum educ* exper* wage* // this is a shortcut to getting all variables // that start with "educ" "exper", etc. // what does educ_mean look like? list educ_mean in 1/20 // this shows the first 20 observations // drop the row mean variables foreach x in educ exper wage { drop `x'_mean } /* Some basic statistics and models ----------------------------------------------------------------------------- */ // correlation matrix correlate educ exper wage correlate educ_dm exper_dm wage_dm // does proxiity to a college increase years of education? reg educ fatheduc motheduc reg* south66 nearcol, robust // does it increase the probability of having a college degree? probit college fatheduc motheduc reg* south66 nearcol logit college fatheduc motheduc reg* south66 nearcol // estimate returns to education reg lwage educ fatheduc motheduc reg* south66 exper expersq, robust // how do you interpret the coef on educ? // use an IV approach ivregress 2sls lwage (educ=nearcol) fatheduc motheduc reg* south66 exper expersq, robust // or use two instruments ivregress 2sls lwage (educ=nearc2 nearc4) fatheduc motheduc reg* south66 exper expersq, robust estat overid // what does this statistic mean? /* Using outreg2 to make tables ----------------------------------------------------------------------------- */ // Installation: Type "findit outreg2", click on "outreg2" and click where it says // click here to install reg lwage educ fatheduc motheduc reg* south66 exper expersq, robust outreg2 using wagetable.txt, replace ivregress 2sls lwage (educ=nearcol) fatheduc motheduc reg* south66 exper expersq, robust outreg2 using wagetable.txt ivregress 2sls lwage (educ=nearc2 nearc4) fatheduc motheduc reg* south66 exper expersq, robust outreg2 using wagetable.txt // There are many options. Type "help outreg2" for the help file. /* Finish up and export the data ------------------------------------------------------------------------------*/ save card2.dta /*----------------------------------------------------------------------------*/ capture log close