0 ratings 0% found this document useful (0 votes) 4 views 4 pages CH 3 Rstudio
The document outlines steps for completing computer exercises in applied econometrics, specifically focusing on multiple regression analysis. It includes examples using datasets from the 'wooldridge' package, demonstrating simple and multiple regression, obtaining predicted values, and calculating residuals. Additionally, it discusses concepts like the Frisch-Waugh theorem, omitted variable bias, and variance of OLS estimates.
AI-enhanced title and description
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
Save Ch 3 Rstudio For Later
GEAESSSESEREA EADS SSUREEEROEESSES EGER EREAEEUEE
# Steps to Complete Computer Exercises
# Applied Econometrics
# Chapter 3: Multiple Regression Analysis
# Author: Imran Arif
GEAROEREGEREREADAEEEROA UREA SESSA TREE EREREEEEE
# Example 3.1
data(gpal, package='wooldridge')
# save the data as mydata.
mydata <- gpal
attach (mydata)
# Define variables
Y <> cbind (coiGPA)
# Simple regression
X <- cbind (ACT)
oLs_sir <- Im(y ~ x)
summary (OLS_siz)
4 Multiple regression
<> cbind (hsGPa, ACT)
ons mir <- Im(y ~ x1)
summary (O3_mlr)
# obtain predicted values
Yohat <- fitted (OLs_mir)
# Regression residuals
[Link] <- resid (OLs_mlz)
# Column bind the above 4 variables.
OLS_fit_resid <- chind(¥, x1, Y-hat, [Link])
GERESESERERER PRES SASGEEE EROS GEREE SEER EREEEREEE
# Example 3.2
data (wagel, package="wooldridge')
attach (wage)
Y <~ chind (Iwage}
X <- chind(educ, exper, tenure)
summary (1m(¥ ~ educ))
ons_wage <- Im(¥ ~ x)
summary (OLS wage)
# obtain predicted values
Yohat <- fitted (OLs_wage)
# Regression residuals
ushat <- resid (OLS_wage)
# Column bind the above 4 variables.
oLS_fit_resid <- cbind(Y, X, Yshat, [Link])
AHOASUAEOEREA PAPA SURO UROAAUOEO ER ER EAEAEEUEE# Partialing out (Frisch-Waugh theorem)
data(wagel, package="wooldridge")
attach (wage)
# Step 1:
BUL_ind <- Im(educ ~ exper + tenure)
4 step 2:
FWL_resid <- resid (FWL_ind)
# step 3:
FWL_parOut <- im(lwage ~ FWL_resid)
summary (FaL_parout)
# Compare with full regression equation
data(gpal, package='wooldridge')
attach (gpal)
# step 1:
FWL_ind <- (1m(hsGPA ~ ACT + age))
summary (FWL_ind)
# step
FWL_resid <- resid(FWL_ind)
4 Step 3:
FWL_parOut <- Im(colGPA ~ FWL_resid)
summary (¥WL_parOut)
summary (Im(colGPA ~ hsGPA + ACT + age)
aeasEeEaEaEaEAEAEECEEEEREE GREE EEER TREE EEEEE
# SER vs, MER Fstimates
# Example 1
data(wage2, package='wooldridge")
attach (wage2)
wage ind <- Im(IQ ~ educ)
summary (wage_ind)
wage_slr <- Im(1wage ~ edu
summary (wage_slr)
wage_mlr <- Im(wage ~ educ + 19)
summary (wage_mlr)
4 Example 2
data(gpal, package='wooldridge')
attach (gpal)
GPA_ind <- Im(ACT ~ hsGPA)
summary (GPA_{nd)
GPA_slr <- Im(colGPA ~ hsGPA)
summary (GPA_slr)
GPA_mir <- Im(colGPA = hsGPA + ACT)summary (GPA_m1r)
AHOOHOROESEOEAEAEAUAEOPREA SHOR GEOR OEORORANAE
# Rosquared
#8xample 1
data(gpal, package:
attach (spat)
*wooldridge')
summary (Im(colGPA ~ ASGPA + ACT))
sc (nsGPA)
example 2
data(crimel, packag
attach (crime)
wooldridge")
summary (Im(nare86 ~ penv + ptimea6 + gemp86))
summary (Im(narr86 ~ penv + avgsen + ptime86 + qemp86))
SEBESERERESEAESEREAERESEADE ESOS ESEREEESEE EOE
# omitted variable bias
data(wage2, packages" wooldridge')
attach (wage?)
wage_mlr <- Im(lwage ~ edue + 19)
summary (wage_mlr)
cor (19, educ)
wage_ind <- Im(ZQ ~ educ)
summary (wage_ind)
wage_six <- Im(1wage ~ educ)
summary (wage_sir)
PUHEEEEE ERE ER ER EE ETO ER EA DEUTER ERO EOR PEA ERE
# The variance of OLS estimates
data(meapsingle, package:
attach (meapsingle)
wooldridge")
# Simple regression model
summary (Im(mathd ~ petsgle))
sc(petagle)* sart ((229-1))
# Multiple regression model with automatic SH:
res <- Im(math4 ~ petsgle + Imedine ~ free)
summary (res)
# Extract SER (instead of calculation via residuals)
(SER <> summary (res) $signa)
# regressing potsgle on lmedinc and free to calcule R2 & VIF
([Link] <- summary(im(pctsgle ~ imedinc + free))$[Link])
([Link] <- 1/([Link]) }# Load package "car" (has to be installed)
Library (car)
# Automatically calculate VIF
vif (res)
# manual calculation of SE of pctsgle coefficien:
n < nobs (res)
SST_petsgle <- sd(meapsingleSpetsgle) * sqrt ((n-1))
([Link] <- SER/SST_petsgle * sqrt ([Link]))