Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Saving multiple parameter estimates


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Saving multiple parameter estimates
Date   Tue, 2 Dec 2003 18:42:55 -0000

Patrick Mcelduff asked 

> I have a dataset with repeat measures on 150 individuals. 
> I want to
> fit a linear regression for each individual (to be used in a
> subsequent analysis). How can I save the slope coefficients for
> each of the 150 regressions?

Ulrich Kohler: 
 
> Use -post- for this task. The following snippet may deal as 
> a starting point. 
> It assumes that you have an identifier-variable "ID" which 
> serially numbers 
> the 150 individuals. If you haven't  such a variable create 
> one with -egen, 
> group- (or use an approach with -levels-). 
> 
> --------------------------------------------------
> post xyz id coef using myfile, replace
> forvalues i = 1/150 {
> 	regress depvar indepvar if id==`i'
> 	post xyz ('i') (_b[indepvar])
> }
> postclose xyz
> ----------------------------------------------------
> 
> Th code stores the coefficients of indepvar and the 
> identifier variable in the Stata-file "myfile.dta". 

Roger Newson: 
 
> Use the -parmest- package, downloadable from SSC, which 
> creates an output 
> data set with 1 observation per parameter and data on 
> estimates, confidence 
> intervals, P-values and other parameter attributes. My 
> Stata Journal 
> article (Newson, 2003) summarises some of the things you 
> can do with 
> -parmest- output data sets, and can be downloaded as a 
> pre-publication 
> draft from my website (see my signature), using either a 
> browser or the Stata -net- command.
> 
> References
> 
> Newson R. Confidence intervals and p-values for delivery to 
> the end user. 
> The Stata Journal 2003; 3(3): 245-269.

Some more possibilities: 

1. -statsby-. Like -post- and -parmest- this 
produces a reduced dataset, or what has been 
called a "resultsset". 

2. -levels- etc. 

e.g. 

levels id, local(I) 

gen slope = . 

qui foreach i of local I { 
	regress ... if id == `i' 
	replace slope = -b[indepvar] if id == `i' 
} 

This produces a variable alongside 
the others in your dataset. 
	 
Nick 
[email protected] 


*
*   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