Dear Statalists,
I would like to add prefixes to all values across multiple label values.
Specifically, I am customizing a dtable and am indenting categorical variables by a couple extra spaces using char(160).
Here is my example code, adding "prefix_" to each value for clarity:
The problem is that each new value label includes quotation marks like so:
I can't figure out how to remove these. There must be something wrong with my use of double quotation marks.
Alternatively, is there a better way of further indenting value labels for categorical variables within dtable or using collect?
Thank you for your time.
Best regards,
Wei
I would like to add prefixes to all values across multiple label values.
Specifically, I am customizing a dtable and am indenting categorical variables by a couple extra spaces using char(160).
Here is my example code, adding "prefix_" to each value for clarity:
Code:
clear all sysuse bplong.dta local categ sex when foreach var of local categ { local valname : value label `var' // get name of value label for variable `var' quietly: label list `valname' // list variable labels local newlabel // reset local label forvalues i = `r(min)'/`r(max)' { local oldsinglelabel : label `valname' `i' // get next label value local newsinglelabel `i' `""prefix_`oldsinglelabel'""' // add prefix local newlabel `newlabel' `newsinglelabel' // local with new label values list } display "`newlabel'" label define `var'_newlabel `newlabel', replace label values `var' `var'_newlabel }
Code:
label list when_newlabel: 1 "prefix_Before" 2 "prefix_After" sex_newlabel: 0 "prefix_Male" 1 "prefix_Female" when: 1 Before 2 After sex: 0 Male 1 Female
Alternatively, is there a better way of further indenting value labels for categorical variables within dtable or using collect?
Thank you for your time.
Best regards,
Wei
Comment