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
RDD with fractional dependent variableDear Stata Community I use the RDD STATA package provided by Calonico, Cattaneo and Titiunik (2015)…
pv command does not allow me to run a second pv-regression on the same datasetHi, I'm using the pv command from the pv package (ssc install pv). It runs a regression for five di…
Cleaning a string variable to create a numerical variableHi, I have station-level electric fuel price variable that is reported in different formats - per ho…
Predicting individual-level slopes and intercepts after running mixed-effects modelsHi All I'm running two linear spline mixed-effects models (growth curve analysis) looking at mental…
RDD with dependent variable as a percentageDear Stata Community After reading the FAQ to the end, I'll try it again, sorry for that. I use th…
Subscribe to:
Post Comments (Atom)
0 Response to Error with rename using local macros
Post a Comment