Hi, I'm looking for a way to access the value labels for a categorical variable, to export them into Excel.
This is my code:
What I'd like is for the question marks to refer to the value labels for age10 (which are 40-49, 50-59 etc), so I can then use that excel file to make a graph.
Come to think of it, is there away to do that excel stuff (import excel, twoway …) in the middle of my do file and then return to the previous state of my original dataset, i.e. without having to re-create all my variables and everything? My solution at the moment is to just have the code for my graph at the bottom of my do file, but it feels like there should be a better way.
I've only just started using Stata for anything more advanced than simple regression commands, and I'm figuring things out as I go along, so I'd welcome any other remarks, like if there's a simpler/better way to do my code.
This is my code:
Code:
putexcel set agegroups.xlsx, modify putexcel A1 = ("Age group") putexcel B1 = ("Coefficient") putexcel C1 = ("se") putexcel D1 = ("l95ci") putexcel E1 = ("u95ci") stcox i.trial##i.age10, nolog scalar counter = 1 forvalues i = 1/4 { lincom 1.trial + 1.trial#`=counter'.age putexcel A`=counter+1' = (?????) putexcel B`=counter+1' = (`=r(estimate)') putexcel C`=counter+1' = (`=r(se)') putexcel D`=counter+1' = ((`=r(estimate)') - 1.96 * (`=r(se)')) putexcel E`=counter+1' = ((`=r(estimate)') + 1.96 * (`=r(se)')) scalar counter = `=counter+1' }
Come to think of it, is there away to do that excel stuff (import excel, twoway …) in the middle of my do file and then return to the previous state of my original dataset, i.e. without having to re-create all my variables and everything? My solution at the moment is to just have the code for my graph at the bottom of my do file, but it feels like there should be a better way.
I've only just started using Stata for anything more advanced than simple regression commands, and I'm figuring things out as I go along, so I'd welcome any other remarks, like if there's a simpler/better way to do my code.
Comment