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
Lags Leads Treatment EffectHello everyone, I unfortunately have another question! I am looking into how to adjust the regress…
identify common ownership of shareholdersDear statalist, I have a set of data with the following variables: year, symbol (symbol of each fir…
How to reduce empty space in the cellHi, I try to reduce or remove empty space in each cell of string variables because it really hinders…
How to draw cubic splines after Cox regressionHello, Could anybody help me with syntaxis to do this graph? y axis= hazard ratio. x axis= covariate…
Interaction plot after poisson regressionHello everyone, after running the following regression: Code: xtpoisson patents cL.ln_xrdintensit…
Subscribe to:
Post Comments (Atom)
0 Response to Help with using expand>2 while replacing values in duplicates generated
Post a Comment