I am trying to write a simple program to combine coefficient and standard error estimates from a set of regression fits. I run, say, 5 regressions, and store the coefficient(s) and standard error(s) of interest into vectors (Stata matrix objects, actually). Then, I need to do the following:
Find the mean value of the coefficient estimates.
Combine the standard error estimates according to the formula suggested for combining results from "multiple imputation". The formula is the square root of the formula for "T" on page 6 of the following document: http://bit.ly/b05WX3
I have written Stata code that does this once, but I want to write this as a function (or "program", in Stata speak) that takes as arguments the vector (or matrix, if possible, to combine multiple estimates at once) of regression coefficient estimates and the vector (or matrix) of corresponding standard error estimates, and then generates 1 and 2 above. Here is the code that I wrote:
(breg is a 1x5 vector of the regression coefficient estimates, and sereg is a 1x5 vector of the associated standard error estimates)
mat ones = (1,1,1,1,1)
mat bregmean = (1/5)*(ones*breg’)
scalar bregmean_s = bregmean[1,1]
mat seregmean = (1/5)*(ones*sereg’)
mat seregbtv = (1/4)*(breg - bregmean#ones)* (breg - bregmean#ones)’
mat varregmi = (1/5)*(sereg*sereg’) + (1+(1/5))* seregbtv
scalar varregmi_s = varregmi[1,1]
scalar seregmi = sqrt(varregmi_s)
disp bregmean_s
disp seregmi
This gives the right answer for a single instance. Any pointers would be great!
UPDATE: I completed the code for combining estimates in a kXm matrix of coefficients/parameters (k is the number of parameters, m the number of imputations). Code can be found here: http://bit.ly/cXJRw1
Thanks to Tristan and Gabi for the pointers.