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
Marginsplot: Changing markers by categorical value along x-axisI am summarizing percentage estimates across cities graphically, using margins and marginsplot. Howe…
behavior of saved outputDear lister I am using Stata17 I want to save the output from 2 table commands in 2 matrixes. Afte…
dyndoc and css formatingHi all. I run the -dyndoc- command in stata15. I include in my code header and css codes. When I s…
Estimate 2SLS with multi-level fixed-effects using ivregress vs reghdfe vs ivreghdfeHello Stata experts, at the moment I'm working on a project that requires the use of 2SLS method wi…
Do Not Rank If ConditionHello, In the sample attached I have ranked var: tfr_lr in var: rank_tfr_lr I would like var: tfr_l…
Subscribe to:
Post Comments (Atom)
0 Response to how to do loop in stata
Post a Comment