Hello,
I have a question about how to do loop in Stata. Say, I have 1000 obs with id from 1 to 1000, and now I want to divide them into 50 groups and assign a group id (gid) from 1 to 50. I can do this by typing:
replace gid = 1 if id<=20
replace gid = 2 if id>20 & id<=40
replace gid = 3 if id>40 & id<=60
replace gid = 4 if id>60 & id<=80
replace gid = 5 if id>80 & id<=100
replace gid = 6 if id>100 & id<=120
...
replace gid = 50 id id>800 & id<=1000
This works, but there will be too much typing. Can anyone help me to write a short loop program to achieve this? Thanks in advance.
Related Posts with how to do loop in stata
How to export descriptive statistics (-desctable- not working)Hello, I am trying to find the best Stata command to export descriptive information into an excel t…
Wrapping up twoway plots using loopHi, Using the codes below, I could nicely plot my data and retain my plots of interest using gr comb…
Interpreting coefficientsHi. I want to interpret the coefficient on the educational categories, where the referent category i…
Summing dollar amount for each unique id for each yearstr50 year str27 state str29 district long regno str110 donortype str109 double amount "2009-2010" "…
Calculate the difference of the value of one observation with the average value for observations in other groupsHi everyone, I have a question of how to use stata to calculate the difference of the value of one …
Subscribe to:
Post Comments (Atom)
0 Response to how to do loop in stata
Post a Comment