Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Averaging coefficients across datasets


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Averaging coefficients across datasets
Date   Fri, 13 Feb 2009 11:37:43 +0000 (GMT)

--- On Thu, 12/2/09, Carlos Rodriguez wrote:
> I have 10 imputed datasets and need to run regressions on each of them
> and then average the coefficients on the explanatory variables across
> them. Unformatunately for my purposes, neither Zelig nor miest or Clarif
> would work.  I'm doing it by hand: running each of my many regressions
> on each of my 10 datasets and then calculating the average for each of
> my many expalnatory varaibles.  This is obvioulsy highly inefficient, so
> I thought I'd ask you if there's a command that would do it in Stata
> automatically or some more efficient way to go about it?

It looks like are trying to multiple imputation by hand. Some time ago I sent an example to the Statalist on how to do that when all imputed files are stacked into one file, but you can easily adapt that example to your own problem. The trick I used is to store the coefficients in matrices, and use Mata to do all the computations. The formulas I used can be found here: http://www.stat.psu.edu/~jls/mifaq.html#howto .

Hope this helps,
Maarten

*------------------------- begin example -----------------------------
sysuse nlsw88, clear
replace wage = . if uniform() < invlogit(5 - .5*grade)

ice wage grade age union, clear m(5)

reg wage grade age union if _mj == 1
matrix b = e(b)'
matrix v = e(V)
matrix V = vecdiag(v)'
reg wage grade age union if _mj == 2
matrix b = b, e(b)'
matrix v = e(V)
matrix V = V, vecdiag(v)'
reg wage grade age union if _mj == 3
matrix b = b, e(b)'
matrix v = e(V)
matrix V = V, vecdiag(v)'
reg wage grade age union if _mj == 4
matrix b = b, e(b)'
matrix v = e(V)
matrix V = V, vecdiag(v)'
reg wage grade age union if _mj == 5
matrix b = b, e(b)'
matrix v = e(V)
matrix V = V, vecdiag(v)'

mata:
b = st_matrix("b")'
V = st_matrix("V")'
Qbar = mean(b)'
Ubar = mean(V)'
B = diagonal(variance(b))
T = Ubar :+ 1.2:*B
se = sqrt(T)
df= 4:* (1 :+ (5:*Ubar):/(6:*B)) :* (1 :+ (5:*Ubar):/(6:*B))
t = Qbar:/se
p = 2*ttail(df, abs(t))
ci = Qbar :- invttail(df,0.025):*se, Qbar :+ invttail(df,0.025):*se
result = Qbar, se, t, df, p, ci
st_matrix("result", result)
end

matrix rownames result = grade age union _cons
matrix colnames result = coef std_err t df p lb ub
matrix list result
*--------------------------- end example --------------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room N515

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------





      

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index