Hello all,
I would like to create the macro for the repetitive work.
The following is the repetitive work:
I would like to have new variable names as er_#.
What I came up with is that:
The commands yield: dr is created to er_2, er_3, and er_4 (Not what I want to).
Instead, I want to create dr =>er2; ds=>er_3; dt=>er_4.
I appreciate any comments.
Best
I would like to create the macro for the repetitive work.
The following is the repetitive work:
Code:
recode dr (1=2 "About half the time (36-65%)") (2=4 "Almost always(91-100%)") (3=0 "Almost never (0-10%)") (4=3 "Most of the time (66-90%)") (5=1 "Sometimes(11-35%)"), gen (er_2) recode ds (1=2 "About half the time (36-65%)") (2=4 "Almost always(91-100%)") (3=0 "Almost never (0-10%)") (4=3 "Most of the time (66-90%)") (5=1 "Sometimes(11-35%)"), gen (er_3) recode dt(1=2 "About half the time (36-65%)") (2=4 "Almost always(91-100%)") (3=0 "Almost never (0-10%)") (4=3 "Most of the time (66-90%)") (5=1 "Sometimes(11-35%)"), gen (er_4)
What I came up with is that:
Code:
foreach Y of varlist dr-ey { forvalues i=2(1)4 { recode `Y' (1=2 "About half the time (36-65%)") (2=4 "Almost always(91-100%)") (3=0 "Almost never (0-10%)") (4=3 "Most of the time (66-90%)") (5=1 "Sometimes(11-35%)"), gen (er_`i') } }
Instead, I want to create dr =>er2; ds=>er_3; dt=>er_4.
I appreciate any comments.
Best
Comment