intro to applied econometrics: basic theory and stata examples · 6/25/18 1 photo credit goes here...
TRANSCRIPT
6/25/18
1
Photo Credit Goes Here
IAPRI-MSU Technical Training
IntrotoAppliedEconometrics:BasictheoryandStataexamples
Trainingmaterialsdevelopedandsessionfacilitatedby
NicoleM.MasonAssistantProfessor,Dept.ofAgricultural,Food,&ResourceEconomics
MichiganStateUniversity
10:00AM–1:00PM,25June2018IndabaAgriculturalPolicyResearchInstitute
Lusaka,Zambia
Why this training?
• RequestedbyIAPRI
• Systematicintroductionfornon-economistandrecentlyhiredeconomistteammembers
• Refresherforinterestedveteraneconomistteammembers
– Ithasbeenawhilesincewelastcoveredthesetopics(2012-2013)!
6/25/18
2
Outline & some questions I hope you’ll be able to answer by the end of today’s session
1. WhatiseconometricsandwhyisitusefulforIAPRI’swork?2. Thesimplelinearregressionmodel
a. Howisitsetup?b. Whatarethekeyunderlyingassumptions?c. Howdoweinterpretit?d. HowdoweestimateitinStata?e. Howdoweuseittotesthypotheses(ingeneral&Stata)?
3. (Time-permitting)Anotherappliedeconometricstopicofyourchoice(e.g.,panelestimators,IV/2SLS,etc.)
What is econometrics? • Whatcomestomindwhenyouheartheword?• Econometricsistheuseofstatisticalmethodsfor:
– “Estimatingeconomicrelationships”– “Testingeconomictheories”– Evaluatingpoliciesandprograms
• Econometricsisstatisticsappliedtoeconomicdata
• WhyiseconometricsusefulforIAPRI?
Source:Wooldridge(2002,p.1)
6/25/18
3
A great resource (this or an earlier version)
Steps in econometric analysis Forthoseofyouthathavedoneapaperthatuseseconometrics,whataresomestepsyouwentthroughingoingfromyourresearchquestion(s)/hypothesis(es)throughtotheanalysisandinference?
1. Researchquestion(s)2. Economicmodelorotherconceptual/theoreticalframework3. Operationalize#2àeconometricmodel4. Specifyhypothesestobetestedin#35. Collectandcleandata;createvariables6. Inspect&summarizedata7. Estimateeconometricmodel8. Interpretresults;hypothesistesting&statisticalinference
Source:Wooldridge(2002,p.1)
6/25/18
4
Economic model vs. econometric model • What’sthedifference?• Economicmodel=“arelationshipderivedfromeconomic
theoryorlessformaleconomicreasoning”– Examples?
• Econometricmodel=“anequationrelatingthedependentvariabletoasetofexplanatoryvariablesandunobserveddisturbances,whereunknownpopulationparametersdeterminetheceterisparibuseffectofeachexplanatoryvariable”– Examples?
Source:Wooldridge(2002,p.794)
Economic model vs. econometric model (cont’d) EX)ModelingdemandforbeefWhatdoeseconomictheorytellusarelikelytobesomecriticalfactorsaffectinganindividual’sdemandforbeef?• Let:
– qbeef=beefquantitydemanded– pbeef=beefprice– pother=avectorofotherprices(complements,substitutes,etc.)– income=income– Z=tastes&preferences(proxiesincaseofeconometricmodel)
• Howcouldwewritedownageneralfunction(economicmodel)relatingbeefquantitydemandedandthefactorslikelytoaffectit?– qbeef=f(pbeef,pother,income,Z)
• Whatwouldthislooklikeitwewerewritingitdownasaneconometricmodel(e.g.,amultiplelinearregressionmodel)?– qbeef=β0+β1pbeef+potherβ2+β3income+Zβ4+u
We’llgothroughnotation/interpretationinafewminutes
6/25/18
5
The simple linear regression model: Motivation • Letyandxaretwovariablesthatrepresentsomepopulation• Wewanttoknow:
– Howdoesychangewhenxchanges?– Whatisthecausaleffect(ceterisparibuseffect)ofxony?
• Examplesofyandx(ingeneralorinyourresearch)?
y xBeefdemand BeefpriceMaizeyield Qtyoffertilizerused
Childnutrition HHreceivessocialcashtransferCropdiversification HHreceivesFISPe-voucherForestconservation Communityforestmgmt.program
Anatomy of a simple linear regression model y=β0+β1x+u
• uistheerrortermordisturbance– ufor“unobserved”– Representsallfactorsotherthanxthataffecty– Someuseεinsteadofu
• Terminologyforyandx?y x
Dependentvariable IndependentvariableExplainedvariable ExplanatoryvariableResponsevariable ControlvariablePredictedvariable Predictorvariable
Regressand RegressorOutcomevariable Covariate
β0(intercept)andβ1(slope)arethe
populationparameterstobeestimated
6/25/18
6
To use data to get unbiased estimates of β0 and β1, we have to make some assumptions about the relationship b/w x and u
y = β0 + β1x + u 1. E(u) = 0 (not restrictive if have an intercept, β0) 2. *** E(u|x) = E(u) (i.e. the average value of u does
not depend on the value of x) #1 & #2 à E(u|x) = E(u) = 0 (zero conditional mean) • If this holds, x is “exogenous”; but if x is
correlated with u, x is “endogenous” (we’ll come back to this later)
What does this assumption imply below? • yield = β0 + β1fertilizer + u, where u is unobserved land quality
(inter alia) • wage = β0 + β1educ + u, where u is unobserved ability (inter alia)
When is this assumption reasonable?
6/25/18
7
Spurious correlations http://www.tylervigen.com/spurious-correlations
What is E(y|x) if we assume E(u|x)=0? y = β0 + β1x + u
What is ∂E( y | x)∂x
and how
do we interpret this result?
∂E( y | x)∂x
= β1
What is the interpretation of β0?
Interpretation: β0 is the expected value of y when x = 0 (intercept)
E(y|x) = β0 + β1x
Hint: Apply the rules for conditional expectations.
Interpretation: β1 is the expectedchange in y given a one unit increase in x, ceteris paribus (slope)
y
x1
2
3
0β
1β slope
intercept
E( y | x) = β0 + β1x
6/25/18
8
Why is it called linear regression? y = β0 + β1x + u
• Linear in parameters, β0 and β1
• Does NOT limit us to linear relationships between x and y
• But rules out models that are non-linear in parameters, e.g.:
y = 1β0 + β1x
+ u
y = Φ β0 + β1x( ) + u
y =β0
β1
x + u
Estimating β0 and β1 y = β0 + β1x + u
• Suppose we have a random sample of size N from the population of interest. Then can write:
yi = β0 + β1xi + ui , i = 1, 2, 3, …, N We don’t know β0 and β1 but want to estimate them.
How does linear regression use the data in our sample to estimate β0 and β1?
6/25/18
9
(Ordinary) least squares (OLS) approach • The estimated values of β0 and β1 are the values
that minimize the sum of squared residuals • “Fitted” values of y and residuals:
Fitted (estimated, predicted) values of y: yi = β0 + β1xi
Source: Wooldridge (2002)
Residuals:ui = yi − yi
= yi − β0 − β1xi
OLS: Choose β0 and β1 to minimize:
ui2
i=1
N∑ = yi − β0 − β1xi( )2
i=1
N∑
yi = β0 + β1xi + ui
The OLS estimators for β0 and β1
β1 =(xi − x )( yi − y)
i=1
N∑
(xi − x )2
i=1
N∑
β0 = y − β1x
6/25/18
10
Ifxis2,whatisyourestimateofy(i.e.,whatisthefittedvaluefory,y-hat)?
Fitted (estimated, predicted) values of y: yi = β0 + β1xi
Basic Stata commands – regressyx Linearregressionofyonx
• EX)regresswageeduc
– predictnewvar1,xb Computefittedvalues
• EX)predictwagehat,xb(Ijustmadeupthenamewagehat)
– predictnewvar2,residComputeresiduals
• EX)predictuhat,resid(Ijustmadeupthenameuhat)
6/25/18
11
Obtaining OLS estimates – example (Stata) Wooldridge (2002) Example 2.4: Wage and education Use Stata to run the simple linear regression of wage (y) on educ (x).
Command: regress wage educ (or: reg wage educ)
β1
β0
wagei = β0 + β1educi + ui
What are β0 and β1 below?
Practice time! 1. Openthedataset“WAGE1.DTA”inStata
a. Typethecommand“describe”toseewhatvariablesareinthedataset
b. Estimatethemodelonthepreviousslide(regwageeduc)c. Findandinterpret(putinasentence!)theestimatesofβ0andβ1in
theregressionoutput2. Openthedataset“RALS1215_training.dta”inStata
a. Use“describe”toseewhatvariablesareinthedatasetb. Regressthevariableforgrossvalueofcropproductiononthe
variableforlandholdingsizec. Findandinterpret(putinasentence!)theestimatesofβ0andβ1in
theregressionoutput
6/25/18
12
Total, explained, & residual sum of squares, R2
SST ≡ ( yi − y)2
i=1
N∑Total sum of squares:
SSE ≡ ( yi − y)2
i=1
N∑Explained sum of squares:
SSR ≡ ui
2
i=1
N∑Residual sum of squares:
SST = SSE+ SSRCoefficient of determination or R2:
R2 = SSE / SST = 1− (SSR / SST )
Proof is on p. 39 of Wooldridge (2002)
Interpretation? The proportion of the sample variation in y that is explained by x
SST (total SS), SSE (explained SS), SSR (residual SS), and R2 in Stata
R2 = SSE / SST = 1− (SSR / SST ) SST = SSE+ SSR
SSE
SSR
SST
6/25/18
13
Practice time! LookattheoutputfromyourRALS-basedregression:1. WhatistheSSE?2. WhatistheSSR?3. WhatistheSST?4. WhatistheR-squared?(Findtheactualnumberandthencheckthatit
equalsSSE/SST)5. InterprettheR-squared(putitinasentence)
Why is it called R2? • Letter R sometimes used to refer to correlation
coefficient (others use ρ, which is “rho”)
R2 is the squared sample correlation coefficient between yi and yi
6/25/18
14
Practice time! ImmediatelyafteryourRALSregressioncommand,usethepreviousslideasaguideand:1. Computethepredictedvaluesofgvharv,callingthemgvharvhat2. Computethecorrelationcoefficientbetweengvharvandgvharvhat3. Squarethiscorrelationcoefficient(usingtheStata“display”command)4. ComparetheR-squaredyoujustcomputed“byhand”totheStata-
generatedR-squaredintheregressionoutput.Dotheymatch?
“My R-squared it too low!”
DoesalowR2meantheregressionresultsareuseless?Whyorwhynot?
y = β0 + β1x
β1 may still be good (unbiased) estimate of ceteris paribus (causal) effect of x on y even if R2 is low
6/25/18
15
Unbiasedness & assumptions needed for it • Whatdoesitmeanforanestimatortobeunbiased?
• WhatassumptionsdoweneedtomakeinorderfortheOLSestimatortobeunbiased?(Hint:wetalkedaboutthekeyassumptionearliertoday.)
E(β1) = β1 and E(β0 ) = β0
Unbiasedness of OLS (simple linear regression) If the following 4 assumptions hold, then OLS is unbiased. (OLS is also consistent under these assumptions, and under slightly weaker assumptions à AFRE 835.)
SLR.1. Linear in parameters:
SLR.2. Random sampling
**SLR.3. Zero conditional mean (exogeneity):
SLR.4. Sample variation in x
y = β0 + β1x + u
E(u | x) = E(u) = 0
β1 =(xi − x )( yi − y)
i=1
N∑
(xi − x )2
i=1
N∑Why necessary? Hint:
6/25/18
16
Can’t estimate slope parameter if no variation in x
Source:Wooldridge(2002)
OLS estimators for β0 and β1 are unbiased under SLR.1-SLR.4
• What does unbiasedness mean in plain language?
• The key assumption is E(u|x) = E(u) = 0 (zero conditional mean/exogeneity) – SLR.3 • Under SLR.1-SLR.4, OLS estimate of β1 is the
causal effect (ceteris paribus effect) of x on y • If E(u|x) ≠ E(u), then x is endogenous to y à OLS
estimates biased à need to take other measures to deal with this (IV/2SLS, panel data methods, etc.)
E(β1) = β1 and E(β0 ) = β0
6/25/18
17
If make one more assumption - homoskedasticity (SLR.5) - then OLS is “BLUE”
LetV(u)=σ2 SLR.5. Homoskedasticity (constant variance):
V (u | x) =V (u) =σ 2
Whichimplies:
V ( y | x) =V (u | x) =σ 2
Homoskedasticity
Source:Wooldridge(2002)
Heteroskedasticity
6/25/18
18
If SLR.1 through SLR.5 hold, then OLS is “BLUE”
• Best(mostefficient,i.e.,smallestvariance)
• Linear(linearfunctionoftheyi)
• Unbiased
• Estimator
Also,ifhomoskedastic,thenthe“regular”varianceformulasforOLSestimatorsarecorrect(i.e.,areunbiasedestimatorsfortruevariances).(Ifheteroskedastic,thentheseformulasandtheregularstandarderrorsreportedbyStatabiasedàtoosmall.)Whyisthisaproblem?
In Stata
V (βi ), i = 0,1
σ2
σ
σ
β ja.k.a.
6/25/18
19
Practice time! LocatethestandarderrorsforyourestimatesintheRALS-basedregressionQuestion:Whydoweneedthesestandarderrors?Howwillweusethem?
The sampling distributions of the OLS estimators • By the Central Limit Theorem, under
assumptions SLR.1-SLR.5, the OLS estimators are asymptotically (i.e., as Nà∞) normally distributed
• If we add one more assumption, then we can obtain the sampling distribution of the OLS estimators in finite samples
SLR.6. Normality: The population error, u, is independent of x and is normally distributed with E(u)=0 and V(u)=σ2, i.e.:
u ~ Normal(0,σ 2 )
6/25/18
20
SLR.1-SLR.6 = “classical linear model assumptions”
• CLM = SLR.1-SLR.6
• CLM assumptions imply y | x ~ Normal(β0 + β1x, σ 2)
Source:Wooldridge(2002)
ByaddingSLR.6,wecandohypothesistestingusingt-statisticseveninfinitesamples
**tdistributionconvergestostandardnormalasd.f.à∞
T =β j − β j
V (β j )~ t with N − 2 d.f.
T-statistic refresher UnderSLR.1-SLR.6(simplelinearregressioncase):
σ
β j
Replaceβjwiththevalueunderthenullhypothesis
e.g., H0 :β j = 0, H1 :β j ≠ 0
6/25/18
21
P-value refresher Whatisap-value?• “Thesmallestsignificancelevelatwhichthenullhypothesiscan
berejected”(Wooldridge2002,p.800)• Significancelevel=P(TypeIerror)
=P(rejectthenullwhenthenullisactuallytrue)• Supposeyouareconductingyourhypothesistestusingthe10%
significancelevelasyourcut-offforstatisticalsignificance• Whatdoyouconcludeifp-value>0.10?Doyourejectthenull
hypothesisoffailtorejectit?• Whatdoyouconcludeifp-value<0.10?
Type I vs. Type II error refresher
TypeIerror:rejectH0whenH0istrueProbability:α(significancelevel)
TypeIIerror:failtorejectH0whenH0isfalseProbability:β(1-β=powerofthetest)–differentβ!
6/25/18
22
T-statistics and p-values in Stata output
The p-values reported by Stata are for H0 :β j = 0 vs. H1 :β j ≠ 0
Practice time! UsingyourRALS-basedregressionoutput:1. Whatisthevalueofthet-statisticthatyouwouldusetotest
H0:βland=0vs.H1:βland≠0?Finditintheregressionoutputandalsocalculateitusingtheformulaafewslidesback.
2. Conductthishypothesistestatthe10%level(usingthep-valuereportedinStata).Whatdoyouconclude?
3. Whatdoesthismeaninpractice?
6/25/18
23
95% confidence intervals in Stata output
Interpretationof95%confidenceinterval(CI):”Ifrandomsampleswereobtainedoverandoveragain,withβjLandβjUcomputedeachtime,thenthe(unknown)populationvalueβjwouldlieintheinterval[βjL,βjU]for95%ofthesamples.Unfortunately,forthesinglesamplethatweusetoconstructtheCI,wedonotknowwhetherβjisactuallycontainedintheinterval.Wehopewehaveobtainedasamplethatisoneofthe95%ofallsampleswheretheintervalestimatecontainsβj,butwehavenoguarantee.”(Wooldridge2002,p.134)
Confidence interval interpretation
βj
Twenty(20)95%CIsforβj
6/25/18
24
95% confidence intervals in Stata output
95%CIsareusefulfortestinghypothesesatthe5%sig.levelaboutvaluesofβjunderthenullotherthanzero(againstthecorresponding2-sidedalternativehypothesis)Ifthevalueofβjunderthenullfallswithinthe95%CI,whatwouldyouconclude?• Failtorejectthenullinfavorofthealternativeatthe5%levelIfthevalueofβjunderthenullisoutsideofthe95%CI,whatwouldyouconclude?• Rejectthenullinfavorofthealternativeatthe5%level
Practice time! Usethe95%CIinyourRALS-basedregressionoutputtotestanullhypothesisofyourchoiceforβj(againstitscorresponding2-sidedalternativehypothesis).Conductyourhypothesistestatthe5%significancelevel.Whatdoyouconclude?
6/25/18
25
(Time-permitting) What else do you want to cover?
Thank you for your attention & participation! NicoleMason([email protected])AssistantProfessorDepartmentofAgricultural,Food,&ResourceEconomics(AFRE)MichiganStateUniversity(MSU)
6/25/18
26
Main reference • Wooldridge,J.(2002).Introductoryeconometrics:Amodernapproach(2ndedition).Cincinnati,OH:South-WesternCollegePub.
EXTRA SLIDES
6/25/18
27
Aside: NPR “Hidden Brain” example of a natural experiment, and when it might be reasonable to assume E(u|x)=E(u) • Listen for the following:
• What is the dependent variable? • What is the main explanatory variable of interest? • Why might it be reasonable to assume E(u|x)=E(u) here? • What is a natural experiment?
• Dependent variable: cognitive function of elderly • Main explanatory variable: wealth • E(u|x)=E(u) might be reasonable – Congress
computational mistake – people in one cohort got higher benefits that next cohort (level of benefits shouldn’t be correlated with unobservables)
Aside: Natural experiments Anaturalexperimentoccurswhensomeexogenousevent—often a change in government policy—changes theenvironment in which individuals, families, firms, or citiesoperate.Anaturalexperimentalwayshasacontrolgroup,whichisnotaffectedbythepolicychange,andatreatmentgroup,whichisthoughttobeaffectedbythepolicychange.Unlikewithatrueexperiment,wheretreatmentandcontrolgroupsarerandomlyandexplicitlychosen, thecontrolandtreatment groups in natural experiments arise from theparticularpolicychange.(Wooldridge,2002:417)
6/25/18
28
Putting it all together: simple linear regression
β1 =(xi − x )( yi − y)
i=1
N∑
(xi − x )2
i=1
N∑
β0 = y − β1x y = β0 + β1x + u
OLSestimatorsforβ0andβ1:
Expectedvalues(underSLR.1-SLR.4): E(β1) = β1 and E(β0 ) = β0
V (β1) = σ 2
(xi − x )2
i=1
N∑
V (β0 ) =σ 2N −1 xi
2
i=1
N∑
(xi − x )2
i=1
N∑
Samplevariances(underSLR.1-SLR.5):
where σ 2 = 1
N − 2ui
2
i=1
N∑ = SSR
N − 2
σ is the standard errorof the regression
A useful cheat-sheet for interpreting models with logged variables
Source:Wooldridge(2002)
β1 =
ΔyΔx
β1
100= Δy
%Δx
100β1 =
%ΔyΔx
β1 =
%Δy%Δx
y = β0 + β1x + u
6/25/18
29
Acknowledgements
ThistrainingwasmadepossiblebythegeneroussupportoftheAmericanPeopleprovidedtotheFeedtheFutureInnovation Lab for Food Security Policy [grant numberAID-OAA-L-13-00001] through the United States AgencyforInternationalDevelopment(USAID).The contents are the responsibility of the trainingmaterial authoranddonotnecessarily reflect theviewsofUSAIDortheUnitedStatesGovernment.
www.feedthefuture.gov