Hi,
I am trying to use the expand command to create duplicates and replacing one of the variables in the row.
For example,
expand 2 if state=="S" & district=="D" & year=="2009", generate (new)
One the duplicate is created, I apply:
replace district="D1" if district=="D" & state=="S" & year==2009 & new==1
This works perfectly only if I want to use expand 2.
Now I want to expand a row 9 times, the replace command will not work as all the new duplicated are assigned the value 1.
To elucidate:
expand 9 if state=="S" & district=="D" & year=="2009", generate (new)
This created the necessary duplicate rows but I can not do the following:
replace district="D1" if district=="D" & state=="S" & year==2009 & new==1
replace district="D2" if district=="D" & state=="S" & year==2009 & new==1
and so on.
I tried generating a case id and replacing it but it requires me to manually check the id created which is not feasible as I need to do this for various states and have a million rows of data.
I am sure there is a better way of doing this which I am missing.
Any help would be appreciated.
Thank you
Regards,
Purnima
Related Posts with Help with using expand>2 while replacing values in duplicates generated
Cutting outliers from qqplotsHi, I have 5 qqplots and for four of them the x and y axis are from 0 to 2. The fifth qqplot goes f…
STATA gets much more slower after PSMI'm working on PSM, and even with same sample and code, my stata suddenly gets slower than before. C…
Identifying how many times Distinct Observations occur within another variable.Hi, I am using panel data from 2008-2019 and I am trying to identify the number of participants who…
Compare levelsof to original var in if conditionI am looping over a variable, running a regression, and extracting the coefficient for each level (t…
Difference-in-differences without baseline (only midline and endline)Dear all, good morning, I am currently dealing with some data issue for an impact evaluation I have …
Subscribe to:
Post Comments (Atom)
0 Response to Help with using expand>2 while replacing values in duplicates generated
Post a Comment