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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: troubleshooting code for simulating survival data |

Date |
Thu, 29 May 2008 17:57:00 +0100 |

As I understand your program, you will get no bootstrap results without at least one covariate, as no scalars are ever defined otherwise. Somewhere you need to define in your program local X <list of covariates> Alternatively, you can use -indeplist- indeplist, local foreach var of local locnames { return scalar `var' = ... } Except that seems a bad idea. You would then get scalars that had idiosyncratic names depending on your covariates. It might be better to do something more like this: indeplist, local local nx : word count `locnames' return scalar nx = `nx' tokenize "`locnames'" forval j = 1/`nx' { return scalar b`j' = exp(_b[``j'']) } That way, your -bootstrap- can pick up whichever of r(b1), r(b2), etc. you want. Michael McCulloch Thank you Nick for pointing out areas of programming I don't yet know well. Three replies: 1. The purpose of my program is to simulate survival data. I want to run this program with -simulate-. (My broader aim is to use these simulated data to validate a Marginal Structural Models program which I'm using on real data.) 2. I wanted -indeplist- because once the model with no covariates works, I'll add them. 3. As for local macro X, that bit of code: foreach var of varlist `X' { return scalar `var' = exp(_b[`var']) } is supposed to give me the hazard ratios for independent variable(s) of the line: stcox a so, how would I modify this to address the "X" issue? Many thanks, Michael >This trace does not add to what you know already. One alternative is to >increase the trace depth, but the program is sufficiently short that >line-by-line scrutiny pays dividends. > >Your bootstrap command expects to see a scalar r(a). > >This will be produced if, and only if, the local macro X contains a. > >But > >First, Svend pointed out that local macro X is never defined by your >program. Nor is it defined by -indeplist-. -indeplist, local- defines a >local locnames, as its help indicates. You do not address this point in >your reply. > >Second, you are calling -stcox- without covariates, so I see no point in >firing up -indeplist- to find out what your covariates are. One of >those things is either wrong or irrelevant. > >I don't understand exactly what your program is trying to do but it does >appear buggy. > >You may also be getting confused between a and `a', which are quite >different beasts. > >The variable `id' does nothing in your program. I don't know if that >matters. My guess is not. > >Nick >n.j.cox@durham.ac.uk > >Michael McCulloch > >Thanks Svend. I've re-run the program preceded by > . set tracedepth 1 > . set trace on >and here is what is returned, but I'm not sure how to understand the >error messages given. > >********* begin command ************* >. capture program drop sim_surv > >. program define sim_surv, rclass > 1. tempname lambda a id t > 2. set obs 10 //create 10 observations > 3. gen `id'=_n //Create ID numbers > 4. set seed 1235 //set random number seed for reproducibility > 5. gen `a'=0 + int(2*uniform()) //Generate treatment: >discrete 0/1 uniform random variable >> s > 6. gen `lambda'=-2 > 7. gen `t'=(ln(uniform())/(`lambda'*exp(-0.8*`a'))) // >using Bender, 2005 > 8. stset `t' > 9. stcox `t' > 10. indeplist, local > 11. foreach var of varlist `X' { > 12. return scalar `var' = exp(_b[`var']) > 13. } > 14. >. end > >. set seed 12358 > >. bootstrap a=r(a), eform reps(10): sim_surv > >********* begin response ************* > >----------------------------------------------------------------------- - >------ >begin bootstrap --- > - version 9, missing > - local version : di "version " string(_caller()) ", missing:" > - if _caller() < 9 { > capture syntax [anything] using [, * ] > if !c(rc) { > if _by() { > error 190 > } > `version' bootstrap_8 `0' > exit > } > } > - capture _on_colon_parse `0' > = capture _on_colon_parse a=r(a), eform reps(10): sim_surv > - if c(rc) | `"`s(after)'"' == "" { > = if c(rc) | `" sim_surv"' == "" { > gettoken old : 0 , qed(qed) > if `qed' { > `version' bootstrap_8 `0' > exit > } > else if "`old'" != "" { > capture which `old' > if !c(rc) { > `version' bootstrap_8 `0' > exit > } > capture program list `old' > if !c(rc) { > `version' bootstrap_8 `0' > exit > } > } > capture syntax [, * ] > if !c(rc) { > if _caller() < 9 { > `version' bootstrap_8 `0' > exit > } > if "`e(prefix)'" != "bootstrap" { > error 301 > } > `version' Display `0' > exit > } > else { > `version' bootstrap_8 `0' > exit > } > } > - preserve > - `version' BootStrap `0' > = version 9.2, missing: BootStrap a=r(a), eform reps(10): sim_surv >(running sim_surv on estimation sample) >'r(a)' evaluated to missing in full sample > >----------------------------------------------------------------------- - >-------- >end bootstrap --- >r(322); > > > >>Michael McCulloch wrote: >> >>I've written the following do-file to simulate survival data, in the >>case of exponential distribution with one treatment variable (a) and >>no covariates. The code works when not in a program, and returns the >>specified Beta-coefficient (-0.8). May I ask for help in fine-tuning >>the program? I'm getting error message: " 'r(a)' evaluated to >>missing in full sample". >> >>clear >>capture program drop sim_surv >> program define sim_surv, rclass >> tempname lambda a id t >> set obs 10 //create 10 observations >> gen `id'=_n //Create ID numbers >> set seed 1235 //set random number seed for reproducibility >> gen `a'=0 + int(2*uniform()) //Generate treatment: discrete >>0/1 uniform random variables >> gen `lambda'=-2 >> gen `t'=(ln(uniform())/(`lambda'*exp(-0.8*`a'))) // using >>Bender, 2005 >> stset `t' >> stcox `t' >> indeplist, local >> foreach var of varlist `X' { >> return scalar `var' = exp(_b[`var']) >> } >> >>end >>set seed 12358 >>bootstrap a=r(a), eform reps(10): sim_surv >> >>============================================================== >> >>It seems that contents of the local macro `X' is not defined within >>the program. That may explain why the code works when not in a >>program, but not in this program. >> >>To examine such problems try: >> >> set tracedepth 1 >> set trace on >> >>Other advice: Tell which command in the program that gave rise to >>the error message, by copying and pasting both command and response >>to you mai.. * * 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**:**Re: st: troubleshooting code for simulating survival data***From:*Svend Juul <SJ@SOCI.AU.DK>

**Re: st: troubleshooting code for simulating survival data***From:*Michael McCulloch <mm@pinest.org>

**RE: st: troubleshooting code for simulating survival data***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**RE: st: troubleshooting code for simulating survival data***From:*Michael McCulloch <mm@pinest.org>

- Prev by Date:
**RE: st: troubleshooting code for simulating survival data** - Next by Date:
**st: RE: Returning a local macro within -simulate- command: Type mismatch error?** - Previous by thread:
**RE: st: troubleshooting code for simulating survival data** - Next by thread:
**st: Reshaping data** - Index(es):

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