//This is the MIDTERM //
//YOUR NAME!!!
//Macros in stata "local" "global"
local poop "C:\Users\abossie\Dropbox\teaching\2017 Spring\Econometrics\stata tutorial"
local test "usdgiufdsgkewugegfoih"
clear
cd "`poop'"
//using macro `whatever'
use birthweight_smoking.dta
local xlist "nprevist alcohol smoker"
reg birthweight `xlist', robust
//sum short for summarize
sum birthweight
//loop
//you could write a line of code for every X variable:
sum nprevist
sum alcohol
sum smoker
//or you could loop through the values of the xlist macro
//stata loop is FOREACH
scalar x=0
foreach q of local xlist {
scalar x=x+1
display "`q' is the"" " x " value in the local macro xlist"
sum `q'
}
reg birthweight nprevist alcohol smoker, robust
//test joint hypothesis
test alcohol smoker
//get predicted value of Y using your estimated coefficents.
predict yhat
sum yhat
//make a graph comparing the relationship between age and birthweight
twoway scatter birthweight age || lfit birthweight age
//if statements
//run a regression that shows the effect of alcohol on birthweight for mothers over 30
drop if age< 30
//drop if age<=29 <= < > >= ==
//drop if age!=30
//you need to put strings in quotes:
//drop if name=="whatever"
reg birthweight alcohol, robust
clear
use birthweight_smoking.dta
//running the same regression without messing up your data (dropping observations)
reg birthweight alcohol if age>=30, robust
//making a graph that includes a regression line for just women 30+
twoway scatter birthweight age || lfit birthweight age || lfit birthweight age if age>=30