I'm trying to create several variables, called Pv1, PV2, PV3, PV4, PV5. I could explain all the details in a comment later, but I think it will be too much if I'd put all the background info in this post.
For each variable, I need to put several conditions. I guess the quickest way to create PV1 is:
Code:
gen pv1=MAT1 if IDSUBJ==1
replace pv1=SCI1 if IDSUBJ==2
replace pv1=REA1 if IDSUBJ==4
replace pv1=(MAT1+SCI1)/2 if IDSUBJ==3
replace pv1=(MAT1+SCI1)/2 if IDSUBJ==6
replace pv1=(SCI1+REA1)/2 if IDSUBJ==7
I'd like to create a forvalue so that the above is looped, with i going from 1 to 5. So:
Code:
forvalues i = 1(1)5 {
gen pvi=MATi if IDSUBJ==1
replace pv1=SCIi if IDSUBJ==2
...etc
Many thanks,
Ahmad
0 Response to Creating a forvalue with several i (or; Generating a new variable with forvalue)
Post a Comment