I was trying to capture variable and value labels as a local macro to use for a K-M plot in Stata 18. The foreach loops runs well independently but when tacked as an include file with other include files, it seems to fail with an error. What could be the glitch? Furthermore, the code deletes the existing var and value labels and switches them to 0 and 1.
Error
// vlabgrabber.doh file below
Code into which above is nestled in.
Error
Code:
. foreach L of local levels { 2. local vl`L': label `vlname' `L' 3. } 0 invalid name r(198); r(198);
// vlabgrabber.doh file below
Code:
* `blab' and level labels macro names are `vl0' `vl1' local blab : variable label `b' levelsof `b', local(levels) local vlname: value label `b' foreach L of local levels { local vl`L': label `vlname' `L' }
Code:
local b cllbtk drop if missing(`b') include ".\gv_includes\vlabgrabber.doh" // Grab var nanme and level labels for graph include ".\gv_includes\kmopt_bin.doh" // KM options for graph sts test `b', logrank local p = chi2tail(`r(df)',`r(chi2)') include ".\gv_includes\pvalkm.do" // Format outputted p-values gvkm2 `b' 5 years // run program for 24 mo K-M plot * add option texts below *------------------------ local title "`blab' adversely impact OS24" local note "" local caption "*Standard errors adjusted for correlation between three centers in HR estimation" *....do not tamper below************************ include ".\gv_includes\kmplotter.do" drop km a0 a1
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte cllbtk 1 0 0 1 0 1 1 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 1 0 1 1 1 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 end label values cllbtk yesno label def yesno 0 "NO", modify label def yesno 1 "YES", modify
Comment