I have about 60 large data sets, each a different round of a repeated survey. I need to construct a single pooled data set containing only a handful of variables.
Some variables (weights, identifiers, demographics) are in every data set and some (substantive questions) are only in some.
The way the weights are stored in the data changed a couple of times, so I need to do slightly different manipulations for data sets from different periods.
The substantive variables I care about have identical labels across the data sets, but completely different names. Other variables have 2-3 variations of both the name and the label.
All the data sets live in the same folder, along with other data sets (additional rounds of the same survey) that don't have any of the substantive variables I need.
I've started doing this the long way (open each file, do the necessary wrangling, save as a new file, with the intention of appending at the end). But there must be a way of doing it in a loop -- maybe I can leverage the nearly-consistent labels?
Specific problem
I am trying to rename my variables to their variable labels. My code is:
Code:
foreach var of varlist _all { local lab: variable lab `var' rename `var' `lab' }
0 Response to Rename variables with labels when labels are multiple words?
Post a Comment