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

From |
Elaine Thomas <e.thomas@cphc.keele.ac.uk> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: Storing coefficients from a stepwise model |

Date |
Tue, 01 Mar 2005 16:41:52 +0000 |

Dear all

Just want to thank David Harrison for his very elegant solutions to my problems...David, you've saved us a lot of transcribing !

Elaine

David Harrison wrote:

You don't say how you are "storing" the coefficients... I will assume it is with something like post, e.g.--

sw logit y x1 x2 x3 x4 x5, pr(.1)

post f (_b[x1]) (_b[x2]) (_b[x3]) (_b[x4]) (_b[x5])

Suppose x2 gets dropped in the stepwise procedure, then this code will produce an error as _b[x2] does not exist. Instead you need to check that each coefficient exists first, e.g.

sw logit y x1 x2 x3 x4 x5, pr(.1)

foreach v of varlist x1 x2 x3 x4 x5 {

cap local b_`v'=_b[`v']

if _rc {

local b_`v'=.

}

}

post f (`b_x1') (`b_x2') (`b_x3') (`b_x4') (`b_x5')

Hopefully this can be adapted to your needs.

David

-----Original Message-----

From: Elaine Thomas [mailto:e.thomas@cphc.keele.ac.uk]

Sent: 01 March 2005 12:53

To: statalist@hsphsun2.harvard.edu

Subject: st: Storing coefficients from a stepwise model

Dear all

I want to perform a stepwise logistic procedure on a number of bootstrapped samples and store the coefficients from each application of the regression in a single file.

I have thus far been able to generate the bootstrapped samples (thanks to David Harrison!) and store the coefficients - however, only if I do not use a stepwise approach to the regression, but simply tell it to fit a model containing a set number of independent variables, say x1 -x5, - this works well. So I get a single new file which contains the coefficients for each cycle, ie

Sample x1 x2 x3 x4 x5

1 0.24 0.35 0.84 0.08 0.75

2 0.22 0.40 0.78 0.12 0.69 ......

The complication in using the sw procedure is that the model derived in each sample may contain anywhere from all to none of the variables offered and when I try to get Stata to store the coefficients for the offered vbls, say x1-x5, I can't get it to store "." for those vbls that are not chosen in that cycle of the procedure

What I want is the same form of file as above but with . or even 0 for those vbls not ending up in the model for that sample, ie.

Sample x1 x2 x3 x4 x5

1 0.24 0 0.84 0.08 0.75

2 0.22 0.40 0.78 0 0.69 ......

Any help would be gratefully received

Best wishes

Elaine Thomas

*

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

Dr Elaine Thomas

Senior lecturer in Biostatistics

Primary Care Sciences Research Centre

Keele University

North Staffordshire

ST5 5BG

Telephone : + 44(0)1782 583924

Fax : + 44(0)1782 583911 Email : e.thomas@keele.ac.uk

*

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

**References**:**st: RE: Storing coefficients from a stepwise model***From:*"David Harrison" <david.harrison@icnarc.org>

- Prev by Date:
**Re: st: Re: Two-way random model for Panel Data** - Next by Date:
**Re: st: Re: Two-way random model for Panel Data** - Previous by thread:
**st: RE: Storing coefficients from a stepwise model** - Index(es):

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