Hello Stata community,
I am trying to replace multiple id of a data set, where the ids are consecutive numbers.
What I need:
replace new_id=149 if man==1 & count_man==1
replace new_id=150 if man==1 & count_man==2
replace new_id=151 if man==1 & count_man==3
replace new_id=152 if man==1 & count_man==4
replace new_id=153 if man==1 & count_man==5
replace new_id=154 if man==1 & count_man==6
replace new_id=155 if man==1 & count_man==7
replace new_id=156 if man==1 & count_man==8
replace new_id=157 if man==1 & count_man==9
I have about 100 ids that need to be changed, therefore I am trying to run a loop. I have tried the following code, but it does not change anything
local obs=1
forvalues x=149/271 {
forvalues i=1/117 {
replace new_id= `x' if man==1 & count_man==`i' in `obs'
}
}
Any suggestions?
Best,
Tatiana
0 Response to Loop with consecutive numbers
Post a Comment