Dear all,
Stata version: 14.1, updated.
I have done some google search with this problem and could not find anything but I am sure it has been discussed before. If anyone can direct me to a relevant link or provide me a solution for the problem below, it will be great.
Problem: I am trying to create Kaplan-Meier graphs on several categorical variables (coded 0/1) in a loop. How can I make the legends to automatically extract the value labels of the categorical variables and apply in a loop. The codes are below and the red fonts require attention. Thanks in advance.
Stata version: 14.1, updated.
I have done some google search with this problem and could not find anything but I am sure it has been discussed before. If anyone can direct me to a relevant link or provide me a solution for the problem below, it will be great.
Problem: I am trying to create Kaplan-Meier graphs on several categorical variables (coded 0/1) in a loop. How can I make the legends to automatically extract the value labels of the categorical variables and apply in a loop. The codes are below and the red fonts require attention. Thanks in advance.
Code:
gr drop _all
loc m=1
foreach var of varlist base help drug rand gender past trt {
sts graph,by(`var') ///
ylab(0.5 (.1) 1, nogrid ang(hor)) xlab(0(10)80) xtitle(" " "Survival weeks") ///
legend(order(1 "Legen group-1 of 1st var" 2 "Legend group-2 of 1st var ") region(col(white))) ///
plot1opts(lpatt(solid) col(black)) ///
plot2opts(lpatt(shortdash) col(black)) ///
graphregion(col(white)) title("")
gr copy x`i',replace
loc ++m
}
Comment