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

Re: st: troubleshooting code for simulating survival data

From   Svend Juul <SJ@SOCI.AU.DK>
Subject   Re: st: troubleshooting code for simulating survival data
Date   Thu, 29 May 2008 13:42:35 +0200

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".

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'])

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

Hope this helps


Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone:  +45 8942 6090
Home:   +45 8693 7796

*   For searches and help try:

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