Hi all, newbie to this listserve--hoping to figure out how to append scalar values to a data file after running multiple time to event simulations.
Currently, following stcox, I generate a new variable from the scalar matrix that I call coeff. Would like to save this value to a separate data file and then when I run the simulation again, append the new scalar value to the separate data file. Objective is to run the simulation ~100 times and end up with a data set of 100 scalar values that I can then average.
set obs 100
gen t25 = -1/.99 * log(1-uniform())
gen t99 = -1/.99 * log(1-uniform())
gen time = min(t99,t25)
gen byte fail = (t25<t99) + 2*(t25>=t99)
replace fail = 0 if time>=2
replace time = 2 if time>2
set obs 200
gen treat = _n>100
*change hazard for treated cohort
*change hazard for first event from 0.25 to 0.1875 (HR=0.75)
replace t25 = -1/.5 * log(1-uniform()) in 100/l
*change HR for second (competing event) from 0.99 to 0.495 (HR=0.50)
replace t99 = -1/.99 * log(1-uniform()) in 100/l
replace time = min(t99,t25)
replace fail = (t25<t99) + 2*(t25>=t99)
replace fail = 0 if time>=2
stset time, f(fail==1) noshow
stcox treat
matrix b=e(b)
svmat b, name(coeff)
**Would like to save the scalar matrix value e(b) to dataset at variable coeff, then send this value to a different file (postfile??)
**Then run simulation again and save next coeff values to the new file etc...
replace t25 = -1/.99 * log(1-uniform()) in 1/100
replace t99 = -1/.99 * log(1-uniform()) in 1/100
replace time = min(t99,t25) in 1/100
replace fail = (t25<t99) + 2*(t25>=t99) in 1/100
replace fail = 0 if time>=2 in 1/100
replace time = 2 if time>2 in 1/100
*change hazard for treated cohort
*change hazard for first event from 0.25 to 0.1875 (HR=0.75)
replace t25 = -1/.5 * log(1-uniform()) in 100/l
*change HR for second (competing event) from 0.99 to 0.495 (HR=0.50)
replace t99 = -1/.99 * log(1-uniform()) in 100/l
replace time = min(t99,t25)
replace fail = (t25<t99) + 2*(t25>=t99)
replace fail = 0 if time>=2
stset time, f(fail==1) noshow
stcox treat
matrix b=e(b)
Currently, following stcox, I generate a new variable from the scalar matrix that I call coeff. Would like to save this value to a separate data file and then when I run the simulation again, append the new scalar value to the separate data file. Objective is to run the simulation ~100 times and end up with a data set of 100 scalar values that I can then average.
set obs 100
gen t25 = -1/.99 * log(1-uniform())
gen t99 = -1/.99 * log(1-uniform())
gen time = min(t99,t25)
gen byte fail = (t25<t99) + 2*(t25>=t99)
replace fail = 0 if time>=2
replace time = 2 if time>2
set obs 200
gen treat = _n>100
*change hazard for treated cohort
*change hazard for first event from 0.25 to 0.1875 (HR=0.75)
replace t25 = -1/.5 * log(1-uniform()) in 100/l
*change HR for second (competing event) from 0.99 to 0.495 (HR=0.50)
replace t99 = -1/.99 * log(1-uniform()) in 100/l
replace time = min(t99,t25)
replace fail = (t25<t99) + 2*(t25>=t99)
replace fail = 0 if time>=2
stset time, f(fail==1) noshow
stcox treat
matrix b=e(b)
svmat b, name(coeff)
**Would like to save the scalar matrix value e(b) to dataset at variable coeff, then send this value to a different file (postfile??)
**Then run simulation again and save next coeff values to the new file etc...
replace t25 = -1/.99 * log(1-uniform()) in 1/100
replace t99 = -1/.99 * log(1-uniform()) in 1/100
replace time = min(t99,t25) in 1/100
replace fail = (t25<t99) + 2*(t25>=t99) in 1/100
replace fail = 0 if time>=2 in 1/100
replace time = 2 if time>2 in 1/100
*change hazard for treated cohort
*change hazard for first event from 0.25 to 0.1875 (HR=0.75)
replace t25 = -1/.5 * log(1-uniform()) in 100/l
*change HR for second (competing event) from 0.99 to 0.495 (HR=0.50)
replace t99 = -1/.99 * log(1-uniform()) in 100/l
replace time = min(t99,t25)
replace fail = (t25<t99) + 2*(t25>=t99)
replace fail = 0 if time>=2
stset time, f(fail==1) noshow
stcox treat
matrix b=e(b)

Comment