Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: shortcut for adjusted means


From   [email protected]
To   [email protected]
Subject   st: shortcut for adjusted means
Date   Wed, 09 Jan 2008 19:47:00 +0100

Has "adjusted mean" a precise meaning for you? Or is it a generic expression, like "regression"?
Also thanks to previous suggestions by Garry Anderson, Kabir Chabal, Nick Cox, Quang Nguyen, Austin Nichols, Valerie Orozco, Dimitris Pavlopoulos, Thomas Steichen, and Tom Trikalinos, I finally managed to translate into Stata an S-Plus script which is said to produce adjusted means, which I need to regress an institution-level variable on individual-level covariates. Any shortcut for producing the same results? Can I have the same from -adjust- and how?
id=1...63 is the panel (institution) identifier; v* are the 15 variables with 354 individual observations which need to be adjusted; x* are more independent variables (with just one observation per panel, i.e. 63); xmean is a matrix of means for collapsed v* (i.e. obtained after -bysort id: gen ns =_N- and then -collapse v* ns, by(id)-); muz is a row of overall means for x*; dz is a matrix of centered x*; ysum is the cumulative sum of the squared values of ns; mux is a matrix of 63 rows (the same row of overall unadjusted means for the UNcollapsed v* is repeated 63 times); d is a matrix of the UNcollapsed v* centered at each panel's mean; d2 is a matrix of the UNcollapsed v* centered at the overall mean.

matcorr x* v*, covariance matrix(vv)
matselrc vv vzz, r(x*) c(x*)
/* To tell the truth, the command doesn't support the use of abridged names.*/    
matselrc vv vzxi, r(x*) c(v*)
matrix mse = d'*d/(354-63)
matrix vu = mse
matrix msa = d2'*d2/(63-1)
scalar cc = (nt - ysum/nt)/(63-1)
matrix vxi = (msa-mse)/cc
matrix r2 = inv(vzz)*vzxi
matrix r1 = vxi - vzxi'*r2
matrix idd = I(15)
forval i=1/63 {
  mat p=inv((r1+vu)/ns[`i'])*r1
  mat q=r2*(idd-p)
  mat xtilde`i' = xmean*p +mux*(idd-p)+dz*q
 mat def row`i' = xtilde`i'[`i'..`i',.]	
	mat def adj = nullmat(adj)\row`i'	
}

Nicola

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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