/* Topics in Data Analysis: Panel Data Models (Winter 2012) homework1.do: answer key for homework assignment 1 Source: http://www.stern.nyu.edu/wgreene/Econometrics/WHO-data.xls Written by Hun Myoung Park, kucc625@iuj.ac.jp Last modified on 02/07/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 // ############################################################################# // Question 1 log using "hw1_log.txt", text replace // import an excel file import excel using WHO.xls, firstrow clear // In version 11 or earlier //version 10 //insheet using http://www.iuj.ac.jp/faculty/kucc625/method/panel/who_health.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 homework1, replace // Question 2 ################################################################## global DV = "comp" global RHS = "hexp hc3 gini geff" regress \$DV \$RHS // Question 3 ################################################################## quietly regress \$DV \$RHS predict r, residuals gen r2=r^2 sum r2 disp r(sum) // print a scalar stored in RAM // Question 4 ################################################################## quietly regress di e(df_m) // degrees of freedom of model (K-1) di e(df_r) // degrees of freedom of error (N-K) di e(N)-1 // degrees of freedom of total (N-1) // Question 5 ################################################################## di e(mss)/e(df_m) // SSM/(K-1) di e(rss)/e(df_r) // SSE/(N-K) // Question 6 ################################################################## di (e(mss)/e(df_m))/(e(rss)/e(df_r)) // MSM/MSE di e(F) // Question 7 ################################################################## // Step 1: State a hypothesis // H0: All parameters of regressors are zero // H1: At least one parameter is not 0 // Step 2: Alpha is .05" // Step 3: P-value is," di Ftail(e(df_m), e(df_r), e(F)) // Step 4: Reject H0 since p-value is smaller than .05 // Step 5: At least one parameter is not zero. // Question 8 ################################################################## quietly regress \$DV \$RHS sum comp // to get the variance of Y local r2 = e(mss)/(r(Var)*(e(N)-1)) // SSM/SST di `r2' di 1-(e(N)-1)/e(df_r)*(1-`r2') // 1-(N-1)/(N-K)*(1-R2) // Question 9 ################################################################## quietly regress \$DV \$RHS di sqrt(e(rss)/e(df_r)) // SEE=SQRT(MSE) di e(rmse) // Question 10 ################################################################## quietly regress matrix list e(b) matrix list e(V) mata // Beginning of Mata language vc = st_matrix("e(V)") // assign a Stata matrix to a matrix in Mata sqrt(diagonal(vc)) // square root of the diagonal elements of variance and covariance matrix end // End of Mata session // Question 11 ################################################################## quietly 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 t = b':/se // calculate t statistics (b', se, t) // print beta, standard error, and t statistic end // End of Mata session // Step 1: The parameter of health expenditure is zero (H0) // Step 2: Alpha is .05 and the critical value is 1.976 (similar to 1.96 since N=150) // Step 3: 2.57 = .0028536655 / .0011091565 // Step 4: Reject the H0 since the test statistic 2.57 is larger than 1.976. // Step 5: The parameter of health expenditure is not zero. // Question 12 ################################################################## quietly regress test hexp=0 disp sqrt(r(F)) // because the degree of freedom of the numerator is 1 // Question 13 ################################################################## 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 t = b':/se // calculate t statistics low_b = b' - 1.976*se // calculate the lower bound high_b = b' + 1.976*se // calculate the upper bound (b', se, t, low_b, high_b) // print beta, standard error, t, and low and upper bounds end // End of Mata session // Step 1: The parameter of educational attainment is zero (H0) // Step 2: Alpha is .05 and the critical value is 1.976 (similar to 1.96 since N=150) // Step 3: [-.7205317214, .9902949141] = .1348816 -/+ 1.976*.4329014766 // Step 4: Do not reject the H0 since the hypothesized value of zero exists within the confidence interval // Step 5: The parameter of educational attainment is zero. // Question 14 ################################################################## regress test hexp+hc3=0 matrix b = e(b) matrix vc = e(V) matrix ts = (b[1,1]+b[1,2])/sqrt(vc[1,1]+vc[2,2]+2*vc[2,1]) matrix ts_2 = ts*ts matrix list ts matrix list ts_2 local t = (.00285367+.1348816)/sqrt(.000001230+.18740369+2*(-.00007073)) di `t' di ttail(e(N)-1, `t')*2 // * There was a mistake in the question 14, which asks to test if both parameters are 0 // Therefore, all students will get 5 points regardless of their answers. // Question 15 ################################################################## // Depending on your choice // Question 16 ################################################################## // Depending on your choice log close // End of homework assignment 1