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
Unsignificant resultsMy name is Muhammad Rashid student of MS BA I have panel data for 10 years of 1600 companies when I …
testing the issue of endogeneityDear all i hope you are doing good actually i would study the issue of endogeneity and i have foun…
xtdpdgmm command - @SebastianKripfganzDear Dr. Kripfganz, Following your suggestions in the previous posts I decided to use xtdpdgmm comm…
Balanced panel?Hello everyone, I have a very simple question that I can't seem to work out an answer to. That is w…
Two stage Program: First stage is OLS and second is mlogit, error in calculating bootstrap standard errorsStata Code: program my2sls regress son_yrs_schooling ib(first).age_cohort father_yrs_schooling ib(l…
Subscribe to:
Post Comments (Atom)
0 Response to how to do loop in stata
Post a Comment