/* Topics in Data Analysis: Panel Data Models (Winter 2012) homework2.do: answer key for homework assignment 2 Source: http://www.stern.nyu.edu/wgreene/Econometrics/WHO-data.xls Written by Hun Myoung Park, kucc625@iuj.ac.jp Last modified on 02/011/2012 *******************************************************************************/ memory // to check memory allocation version 12 // to set the version of interpreter set more off // to tell Stata not to pause when output is long cd c:\temp // to set a default directory // ############################################################################# log using "hw2_log.txt", text replace // import an excel file import excel using WHO.xls, firstrow clear // In version 11 or earlier //version 10 //insheet using WHO.csv, comma names clear // change variable names from uppercase to lowercase foreach v of varlist Zimbabwe-LGDPC2 { local new_v = lower("`v'") // local macro rename `v' `new_v' } save WHO, replace // store original file rename country cnt_code gen country = real(cnt_code) // convert a string to a number keep if groupti==5 // get balanced panel data keep if oecd==1 save homework2, replace // Question 1 ################################################################## global OLS = "comp hexp hc3 gini geff" regress \$OLS forvalues i=93/97 { gen year`i'=(year==19`i') // e.g., gen year93=(year==1993) } sum year93-year97 // Question 2 ################################################################## global D0 = "year93 year94 year95 year96 year97" global D1 = "year93 year94 year96 year97" // Question 2.1 ===================== regress \$OLS \$D1 // Question 2.2 ===================== // Step 1: H0: all parameters of regressors are zero; H1: at least one parameter is not zero // Step 2: Alpha is .05 // Step 3: F statistic and P-value are di "F = " e(F) " Df of Model: " e(df_m) " Df of Error: " e(df_r) di "P-value: " Ftail(e(df_m), e(df_r), e(F)) // Step 4: Reject H0 since p-value < Alpha // Step 5: At least one parameter is not zero. // Question 2.3 ===================== di "SSE: " e(rss) " SEE: " e(rmse) " Df of Error: " e(df_r) " R2: " e(r2) // Question 2.4 ===================== regress mata // Beginning of Mata language b = st_matrix("e(b)") vc = st_matrix("e(V)") se = sqrt(diagonal(vc)) // get diagonal elements from the variance-covariance matrix (b', se) // print beta, standard error, and t statistic end // End of Mata session // Question 2.5 ===================== regress \$OLS \$D1 forvalues j=5/8 { matrix b = e(b) local b0 = b[1, 9] // baseline intercept local b`j' = b[1, `j'] // deviation from the baseline local b_star = `b0' + `b`j'' // actual intercept di `b_star' " + " b[1, 1] " hexp + " b[1, 2] " hc3 + " b[1, 3] " gini + " b[1, 4] " geff" } // Question 2.6 ===================== // The intercept of LSDV1 is the intercept of the group (entity) whose dummy variable was dropped. // Question 2.7 ===================== local b2 = b[1,2] local max = 2 twoway function year95=`b0' + `b2'*x, range(0 `max') lwidth(thick) lstyle(foreground) /// || function year93=`b0' + (`b5')+ `b2'*x, range(0 `max') lwidth(thin) color(yellow) /// || function year94=`b0' + (`b6')+ `b2'*x, range(0 `max') lwidth(thin) color(blue) /// || function year96=`b0' + (`b7')+ `b2'*x, range(0 `max') lwidth(thin) color(red) /// || function year97=`b0' + (`b8')+ `b2'*x, range(0 `max') lwidth(thin) color(green) /// , ylabel(86(1)90) xlabel(0(.2)`max') legend(on) /// title("Regression Lines for Five Years", position(12)) // Question 2.8 ===================== quietly regress \$OLS \$D1 matrix V = e(V) // Step 1: H0: the parameter of year 1997 is zero; H1: the parameter year 1997 is not zero // Step 2: Alpha is .05 // Step 3: local t = b[1,8]/sqrt(V[8,8]) di "T statisitc is " `t' " and p-value is " ttail(e(df_r), `t')*2 // Step 4: Do not reject H0 since p-value > alpha // Step 5: The parameter of year 1997 (deviation from the baseline intercept) is zero. // Question 2.9 ===================== // The deviation of the actual intercept of year 1997 from the baseline intercept (1995). // Question 2.10 ===================== quietly regress \$OLS \$D1 test year93 year94 year96 year97 // Step 1: H0: all four dummy parameters are zero; H1: at least one dummy parameter is not zero // Step 2: Alpha is .05 // Step 3: di "F statistics is " r(F) " and the p-value is " r(p) // Step 4: Do not reject H0 since p-value > alpha // Step 5: All four dummy parameters are zero. // Therefore, the inclusion of four dummy variables did not improve the model. // Question 2.11 ===================== regress \$OLS year94-year97 // all goodness-of-fit measures and parameters of regressors remain unchanged. // Question 2.12 ===================== forvalues j=5/8 { matrix b = e(b) local b0 = b[1, 9] // baseline intercept local b`j' = b[1, `j'] // deviation from the baseline local b_star = `b0' + `b`j'' // actual intercept di `b_star' " + " b[1, 1] " hexp + " b[1, 2] " hc3 + " b[1, 3] " gini + " b[1, 4] " geff" } // Five regression lines are identical to those obtained in Q 2.5 // The intercept is the actual intercept of year 1993. // the coefficient of year 1997 is the deviation of 1997 intercept from the baseline intercept // Question 2.13 ===================== xi: regress \$OLS i.year // Yes, the models in Q2.11 and Q.2.13 are identical // Question 3 ################################################################## // LSDV 2 // Question 3.1 ===================== regress \$OLS \$D0, noc // Question 3.2 ===================== di "SSE: " e(rss) " SEE: " e(rmse) " Df of Error: " e(df_r) " R2: " e(r2) " Adj. R2: " e(r2_a) // All statistics except for R2 and Adj. R2 remain unchanged // Question 3.3 ===================== matrix b = e(b) matrix V = e(V) forvalues i = 1/2 { local b`i' = b[1,`i'] // parameter estimators local se`i' = sqrt(V[`i',`i']) // standard errors di `i' " : " `b`i'' " " `se`i'' } // They are identical to those of LSDV1 // Question 3.4 ===================== forvalues j=5/9 { matrix b = e(b) di "Year " 1988+`j' " : " b[1,`j'] " + " b[1, 1] " hexp + " b[1, 2] " hc3 + " b[1, 3] " gini + " b[1, 4] " geff" } // Question 3.5 ===================== // Step 1: H0: the intercept of year 1997 is zero; H1: the intercept year 1997 is not zero // Step 2: Alpha is .05 // Step 3: local t = b[1,8]/sqrt(V[8,8]) di "T statisitc is " `t' " and p-value is " ttail(e(df_r), `t')*2 // Step 4: Reject H0 since p-value < alpha // Step 5: The parameter (actual intercept)of year 1997 is not zero. // Question 3.6 ===================== // The dummy parameter is the actual intercept of Year 1997. // Question 4 ################################################################## // LSDV 3 // Question 4.1 ===================== //version 9 If you dont want to use "collinear" option, change command interpreter constraint 1 year93 + year94 + year95 + year96 + year97 = 0 cnsreg \$OLS \$D0, constraint(1) collinear // Question 4.2 ===================== di "SSE: " (e(rmse)^2)*e(df_r) " SEE: " e(rmse) " Df of Error: " e(df_r) " // SEE and Df of error are the same as those in LSDV1. // .cnsreg does not report R2 and Adj. R2 // Question 4.3 ===================== matrix b = e(b) matrix V = e(V) forvalues i = 1/2 { local b`i' = b[1,`i'] // parameter estimators local se`i' = sqrt(V[`i',`i']) // standard errors di `i' " : " `b`i'' " " `se`i'' } // They are identical to those of LSDV1 // Question 4.4 ===================== forvalues j=5/9 { matrix b = e(b) local b0 = b[1, 10] // baseline intercept local b`j' = b[1, `j'] // deviation from the baseline local b_star = `b0' + `b`j'' // actual intercept di "Year " 1988+`j' " : " `b_star' " + " b[1, 1] " hexp + " b[1, 2] " hc3 + " b[1, 3] " gini + " b[1, 4] " geff" } // Question 4.5 ===================== regress \$OLS \$D0, noc matrix b = e(b) forvalues i = 5/9 { local b`i' = b[1,`i'] } di `b0' " = (" `b5' " + " `b6' " + " `b7' " + " `b8' " + " `b9' ") / 5" // Question 4.6 ===================== version 9 constraint 1 year93 + year94 + year95 + year96 + year97 = 0 cnsreg \$OLS \$D0, constraint(1) matrix b = e(b) matrix V = e(V) // Step 1: H0: the parameter of year 1997 is zero; H1: the parameter of year 1997 is not zero // Step 2: Alpha is .05 // Step 3: local t = b[1,9]/sqrt(V[9,9]) di "T statisitc is " `t' " and p-value is " ttail(e(df_r), `t')*2 // Step 4: Do not reject H0 since p-value > alpha // Step 5: The parameter (deviation from the averaged intercept) of year 1997 is not zero. // Question 4.7 ===================== // The dummy parameter is the deviation of the actural intercept of year 1997 from the // averaged intercept (overall intercept). log close // End of homework assignment 2