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
Related Posts with Loop with consecutive numbers
weighted varibles for latent class modelHi Scholars, I have a dataset that overrepresented respondents in some of important socio-demograph…
Interaction Using Single Hashtag (#)Dear Experts, My objective is to get two coefficients with corresponding p-values before and after …
Coefplot - without any FEDear Statalist users, I'm trying to make a plot of my regression results using coefplot. I have dat…
Distance between two coordinatesGoodmorning, I want to calculate the distance between two x,y coordinates. However, I have a list of…
How to Append Logistic Regression Outputs Using ASDOCHi, Stata Users: Can someone please demonstrate how to append logistic regression outputs using the…
Subscribe to:
Post Comments (Atom)
0 Response to Loop with consecutive numbers
Post a Comment