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
Within estimator estimateI have the following equation: Array in my data I have year and Id I want to get the within the pa…
Querying multiple variables at a timeHi everyone, I am working in a database where each patient has fifteen procedure variables: proc1 pr…
Poisson command on panel datawhen i run the following commnad xtpqml lexp_food year mig_stats_16 mig_stats_yr sex sector edu_hh e…
Repeated time values within panel when declaring Panel DataHi all, I have a panel data on bilateral trade volume of 55 country pairs for 15 years time period …
asdoc : addition of bysort prefix with tab, tab1, tab2 commandsI have just added support for the bysort prefix with tabulation commands in asdoc. Details and examp…
Subscribe to:
Post Comments (Atom)
0 Response to how to do loop in stata
Post a Comment