I importing many excel files with long variables names and lots of space. The truncated variable names do not work my purposes. So I need to shorten the labels into workable variable names.
I have gotten this code to work until the rename step, but I am not seeing the (probably very obvious error) in the rename step.
clear
set obs 2
gen ShelteredESHomelessPeoplein = 1
label variable ShelteredESHomelessPeoplein "Sheltered ES Homeless People in Families, 2007"
foreach v of varlist _all {
di "`v'"
local wholename : variable label `v'
di "`wholename'"
local new = substr(subinstr("`wholename'", " ", "",.),1,30)
di "`new'"
di "`v'" " " "`new'"
rename "`v'" " " "`new'"
}
Thanks in advance
Related Posts with Error with rename using local macros
Stata margins command (atmeans) for one standard deviation changeHi everyone, I am currently writing my Bachelor thesis and need some help with the margins command.…
Non proportionality of Cox model, using piece-wise constant exponential model insteadHi, I am studying union formation and dissolution of first and second-generation immigrants in the h…
Granger-causality testHello Is it possible to perform a Granger-causality test including an instrumental variable using pa…
Controlling the space occupied by a axis labelsHi all, I am trying to create a panel graph of two histograms and a scatter using graph combine. T…
Creating variablesDear Stata forum members, I would like some help with the creation of certain variables. The varia…
Subscribe to:
Post Comments (Atom)
0 Response to Error with rename using local macros
Post a Comment