Statalist The Stata Listserver


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

st: Re: FW: Accumulating parameter estimates


From   Marcello Pagano <[email protected]>
To   [email protected]
Subject   st: Re: FW: Accumulating parameter estimates
Date   Wed, 13 Jun 2007 06:15:24 -0400

Nick Cox wrote:
-----Original Message-----
From: Nick Cox Sent: 13 June 2007 10:31
To: '[email protected]'
Subject: RE: Accumulating parameter estimates



Roger Newson explained how to do it his way
and Michael Blasnik pointed to -statsby-. Those are good solutions. Here's another. Start by reading in your data (just once): use statafile, clear
Initialise variables to hold your results: gen beta = . gen se = . Now cycle over your -id-s: levelsof id, local(I) foreach i of local I { glm ... if id == `i' replace beta = ... if id == `i' replace se = ... if id == `i' }
The ... you need to fill in as appropriate. If you want that done quietly, slap -quietly- in front of the -foreach-.
Now each beta value (etc.) is repeated for each observation with the same identifier. For any purpose for which you want just one observation from each identifier, you can do this: egen tag = tag(id) ... if tag
Keeping the results with the original data
greatly eases various possible analyses downstream, in which
you want to relate parameter estimates, standard errors, etc. to other variables in the data. Key points here: 1. There is no need for endless cycling over -use- and -keep-. Exploit -if- to the full. 2. Results can be built up and kept in the same dataset. 3. I'm assuming your -id- is numeric, as implied by your own code. Nick [email protected]
Garth Rauscher

I have a feeling this is a pretty straightforward issue but cannot figure it
out. I'd like to run a large number of identical models on a large number of
hypothetical datasets (all contained within the master file "statafile" and
identified by a unique ID), while accumulating paremeter estimates and
standard errors into an output dataset. Below is my code, please see the
parts in parentheses-- any help is appreciated.

/* RUN THE FIRST MODEL AND CREATE A BASE DATASET FOR APPENDING */

use statafile, clear
keep if id == 1
glm y x [fweight=n], family(binomial) link(identity) noheader

(How to save beta and standard error for X in a "base" dataset?)


/* RUN THE REST OF THE MODELS AND APPEND TO THE BASE */

forvalues i = 2/100{
use statafile, clear
keep if id == `i'
glm y x [fweight=n], family(binomial) link(identity) noheader

(How to save beta and standard error for X in a dataset)
(How to append to the base dataset and accumulate rows)

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