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
Add Time in Panel RegressionHello Statalist, As a beginner, I am asking a silly and simple question. In my panel data model. th…
How to scalar matrixes produced by mean, over() for exact groupsDear all, I am trying to find a way to store vector of mean estimates as scalars. In fact, I compar…
new Mata class abm_nw for managing networks in an Agent Based ModelA new Mata class called abm_nw is now available from this GitHub repository. It is intended to help …
Combining several tablesDear Statlists, I am trying to combine several tables into one table. in the following code I creat…
Panel data analysisHi evryone. What is wrong in may data? I cannot do xtpcse analysis. Please HELP!!! …
Subscribe to:
Post Comments (Atom)
0 Response to Loop with consecutive numbers
Post a Comment