Automatic labelling of newly created indicator variables in Stata -
i have variable called region
, has 22 elements. here output of tabulate region
:
region of place of work | freq. percent cum. ---------------------------+----------------------------------- tyne & wear | 6 1.20 1.20 rest of northern region | 12 2.40 3.60 south yorkshire | 9 1.80 5.40 west yorkshire | 23 4.60 10.00 rest of yorks & humberside | 9 1.80 11.80 east midlands | 42 8.40 20.20 east anglia | 12 2.40 22.60 central london | 41 8.20 30.80 inner london (not central) | 23 4.60 35.40 outer london | 19 3.80 39.20 rest of south east | 97 19.40 58.60 south west | 46 9.20 67.80 west midlands metropolitan | 29 5.80 73.60 rest of west midlands | 14 2.80 76.40 greater manchester | 15 3.00 79.40 merseyside | 2 0.40 79.80 rest of north west | 31 6.20 86.00 wales | 12 2.40 88.40 strathclyde | 23 4.60 93.00 rest of scotland | 27 5.40 98.40 northern ireland | 8 1.60 100.00 ---------------------------+----------------------------------- total | 500 100.00
i have created indicator variables using tab region, gen(region_)
. creates 22 new variables, region_1
region_22
. do want indicator variables have simple names region_1
, etc (e.g. more easy call using region_*
). problem label of variable, region==south west
. want south west
.
i have looked @ dummieslab
(ssc) focuses on adding labels new variable names. none of these solutions work either. know automatic way obtain this? simple function eliminating specific words labels (getting rid of region==
bit) work. can't find it.
loop on variables , zap unwanted text label each time. basic functionality documented @ help macro
, in corresponding manual entry.
foreach v of var region_* { local lbl : var label `v' local lbl : subinstr local lbl "region==" "", local lbl = trim("`lbl'") label var `v' "`lbl'" }
for canned solution, see labvarch
labutil
on ssc, can install
ssc inst labutil
Comments
Post a Comment