SHARE
TWEET

Wald test in Stata

aidanhorn Apr 13th, 2019 (edited) 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. * Note that x = 1993 and y = 1998.
  2.  
  3. cap drop Insample
  4. mark Insample if logpay93 !=. & logpay98 != .
  5. summ Insample
  6. scalar N = r(sum)
  7.  
  8. * 1st entry of covariance matrix
  9. corr logpay93 logpay98, cov
  10. scalar var_mu93_minus_mu98 = (r(Var_1)*(r(N) - 1)/r(N) + r(Var_2)*(r(N)-1)/r(N) - 2*r(cov_12)*(r(N)-1)/r(N))/N
  11. // Stata computes the sample estimates, but we are working with MLEs
  12.  
  13. * 2nd and 3rd entries (cov_mus_vars)
  14. foreach y in 93 98 {
  15. summ logpay`y', detail
  16. scalar mu_`y' = r(mean)
  17. scalar var_`y' = r(Var)*(r(N) - 1)/r(N)
  18. gen logpay`y'deviation2 = (logpay`y' - mu_`y')^2
  19.  
  20. correlate logpay`y' logpay`y'deviation2, covariance
  21. scalar cov_`y'_`y'deviation2 = r(cov_12)*(r(N) - 1)/r(N)
  22. scalar var_`y'deviation2 = r(Var_2)*(r(N)-1)/r(N)  // comes in handy for the final entry
  23. display cov_`y'_`y'deviation2
  24. }
  25.  
  26. corr logpay93 logpay98deviation2, cov
  27. scalar cov_93_98deviation2 = r(cov_12)*(r(N) - 1)/r(N)
  28. display cov_93_98deviation2
  29.  
  30. corr logpay98 logpay93deviation2, cov
  31. scalar cov_98_93deviation2 = r(cov_12)*(r(N) - 1)/r(N)
  32. display cov_98_93deviation2
  33.  
  34. scalar cov_mus_vars = ( cov_93_93deviation2 - cov_93_98deviation2 - cov_98_93deviation2 + cov_98_98deviation2 )/N
  35. display  cov_mus_vars
  36.  
  37.  
  38. * 4th entry
  39. correlate logpay93deviation2  logpay98deviation2, cov
  40. scalar cov_dev2s = r(cov_12)*(r(N) - 1)/r(N)
  41.  
  42. scalar var_vars = ( var_93deviation2 + var_98deviation2 - cov_dev2s )/N
  43.  
  44. di var_mu93_minus_mu98
  45. cap drop Cov_theta
  46. matrix define Cov_theta = ( var_mu93_minus_mu98 , cov_mus_vars \  cov_mus_vars, var_vars )
  47. matrix list Cov_theta, nohalf // note that only the lower triangle will be printed if "nohalf" is not specified, as this matrix is symmetric
  48.  
  49. matrix inv_Cov_theta = invsym(Cov_theta)
  50. matrix list inv_Cov_theta
  51.  
  52. matrix define theta = ( mu_93 - mu_98 \ var_93 - var_98 )
  53. mat thetarow = theta'
  54.  
  55. matrix Wald_joint_matrix = thetarow*inv_Cov_theta*theta
  56. scalar Wald_joint = Wald_joint_matrix[1, 1]
  57. di Wald_joint // Wald statistic
  58. di chi2tail(2, Wald_joint) // p-value
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top