Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65533

Automating an stcox command in a loop and outputting the result to another file.

$
0
0
I am fairly new to Stata.
I have survival data for 60 patients. I have asked a large number of physicians to evaluate each of the patients and say whether they think the patient has a killer disease - so, a binary evaluation of 1 = yes, has the disease, 0 = no, does not have the disease. Each doctor is labeled var1.....varN). Here is what the data looks like for the first 10 patients and for 3 doctors (var1-var3):

Code:
input byte(patient dead var1 var2 var3)
1 0 0 0 0
2 0 0 0 0
3 0 1 1 1
4 1 0 0 0
5 1 0 1 1
6 0 0 0 0
7 1 1 1 1
8 1 0 0 0
9 1 0 0 0
10 1 0 0 1
end
I can easily perform a stcox var1 to see the prognostic significance of the doctor's ( in this case, labeled var1) diagnosis. The issue is, that I may have up to 1000 doctors which makes performing a stcox for each very cumbersome. Ideally I could write the results to another file. This what I have tried - posting the result to another file called test.dta.

Code:
tempname memhold
postfile `memhold' survival using "test.dta" , replace
foreach var in varlist var1-var10 {
post `memhold' (`stcox(var)')
}
postclose `memhold'
I can see at least one reason why this doesn't work - I think that the line

Code:
post ` memhold ' (` stcox (var)')
Isn't specifying one value but instead a set of results. The ideal situation would be to "post" the HR, p value and CI to another file. That file would look like this:

Code:
doctor  hr       p       CIlwr       CIupper
"var1"  4.341    .003   1.672851 11.26876
"var2"  2.595   .031  1.092362 6.165455
"var3"  6.160    0      2.430396 15.61521
I am sure there is an easy way to do this. May I ask for some assistance?

Viewing all articles
Browse latest Browse all 65533

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>