/* Sample code to get started with Stata */
#delimit ; /* Means ; will indicate end of commadn, similar to matlab */
drop _all; /* Makes sure we don't have any var's in memory */
discard; /* Makes sure we haven't any stored locals, globals, or such in memory (overcourse for now) */
/* Loading a Stata data set from course website */
use http://www.nippelagerlof.com/teaching/7110/ExampleSpatialData_July_2015_1, clear;
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Naming variables */
label var dep "Dependent variable";
label var indep1 "Independent variable 1";
label var indep2 "Independent variable 2";
label var indep3 "Independent variable 3";
label var indep4 "Independent variable 4";
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Regressions */
noisily regress dep indep1 indep2 indep3 indep4, robust; /* OLS regression command that is reported results window */
n reg dep
indep1 indep2 indep3 indep4, robust; /* Same as above but shorter, and on two lines */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Figures */
twoway (scatter dep indep1); /* Scatter plot figure */
twoway (scatter dep indep1 if indep2<.15); /* Scatter plot for subsample */
twoway (scatter dep indep1, msymbol(none) mlabel(C1) mlabposition(0)); /* Scatter plot with C1 as marker label positioned at value */
twoway (scatter dep indep1, mcolor(red) msize(large) msymbol(X)); /* Scatter plot with more marker variations */
twoway
(scatter dep indep1, mfcolor(ltblue) mlcolor(red) msize(large) msymbol(o) )
(lfit dep indep1, lpattern(--) lcolor(blue) lwidth(medthick));
/* Scatter plot + reg line + new symbols */
twoway
(scatter dep indep1, mfcolor(ltblue) mlcolor(red) msize(large) msymbol(o) ytitle("Nippe") title("Look at this cool graph"))
(lfit dep indep1, lpattern(--) lcolor(blue) lwidth(medthick)
legend(size(small) order(- "What things mean:" 1 "Data" 2 "Fit")
cols(1) position(11) ring(0)))
; /* Adding legend to above plot, plot title and y-axis label */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Saving, exporting graphs; note must adjust folder locations below */
/* Set current directory; all files saved go here */
cd "C:\Work\NewHomepage\Teaching\7110\Stata";
/* Saving a graph as stata fig (gph) */
graph save Graph
"TestFig_Feb2017_1.gph", replace;
/* Exporting to eps format */
graph export
"TestFig_Feb2017_1.eps",
as(eps) replace;
/* Exporting to pdf format */
graph export
"TestFig_Feb2017_1.pdf",
as(pdf) replace;
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Regression tables again */
n reg dep indep1, robust;
est store Col1;
n reg dep indep1 indep2, robust;
est store Col2;
n reg dep indep1 indep2 indep3, robust;
est store Col3;
n reg dep indep1 indep2 indep3, robust;
est store Col4;
/* Creating CSV table using esttab */
n esttab
Col1 Col2 Col3 Col4
using TestStataTableFeb2017_1.csv, replace
starlevels(* 0.10 ** 0.05 *** 0.01)
order(indep1 indep2 indep3 indep4)
label
title("OLS regressions with robust standrad errors")
b(3) se(2) r2(2)
nogaps obslast nocon;