Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Bootstrapping stepwise selected survival analysis variables


From   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Bootstrapping stepwise selected survival analysis variables
Date   Thu, 26 May 2011 14:27:12 +0200

On Thu, May 26, 2011 at 1:40 PM, Louis, Philippe wrote:
> I am developing a survival analysis model. The regression coefficients were selected using the stepwise forward method:
> stepwise, pr(.15) pe(.05) forward : stcox VARIABLES, vce(cluster VARIABLE)
>
> I would like to use a bootstrap re-sampling procedure to study the stability of the stepwise selected model.
> Thus, I am interested in determining which variables are consistently selected using bootstrapping with replacement from the original sample.

*------------------------------------- begin example
-------------------------------------
// data preparation
webuse nhefs, clear
stset age_lung_cancer if age_lung_cancer < . [pw=swgt2], fail(lung_cancer)
gen byte married = marital_status == 2 if marital_status < .
gen byte black = revised_race == 3 if revised_race < .
tempfile orig
save `orig'

// preparations for the loop
tempfile results
tempname b memhold
local vars "former_smoker smoker male urban1 rural married black"
postfile `memhold' `vars' using `results'
local k = 20
_dots 0, title(Selecting varialbes in bootstrap samples) reps(`k')

// k (in this case 20) bootstrap samples
forvalues i = 1/`k' {
	// get the bootstrap sample and estimate model
	use `orig', clear
	bsample
	capture stepwise, pr(.15) pe(.05) forward : stcox `vars'

	// gives you something to look at while the loop is running
	nois _dots `i' `=_rc'
	
	// get names of included variables
	matrix `b' = e(b)
	local incl : colnames `b'
	
	// reset local res to empty
	local res ""
	
	// a variable gets a 1 if included and a 0 when not
	foreach var of local vars {
		if `: list var in incl' {
			local res "`res' (1)"
		}
		else {
			local res "`res' (0)"
		}
	}
	
	// post those results
	post `memhold' `res'
}
postclose `memhold'

// look at the results
use `results', clear
sum
list
*------------------------------- end example ------------------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index