Hello, Everyone,
I want to assign individuals (id) into groups of five (group) in the following pattern -- how should I write stata code using "foreach" or maybe "forvalue"?
replace group=1 if id>=1 & id <=5
replace group=2 if id>=6 & id <=10
replace group=3 if id>=11 & id <=15
replace group=4 if id>=16 & id <=20
replace group=5 if id>=21& id <=25
.......
Thanks a lot!
Related Posts with Need Help on STATA loop
How to produce a predicted graph between dependent and independent variables, keeping all other variables constant?How to produce a predicted graph between a dependent and an independent variable (both continuous va…
Issues with string variable that takes numeric values ('1', '2', ...)I read in a dataset that includes many columns of categorical variables denoted by '1', '2', ... 1)…
Fixed & Random Effects with noisy ESG (sustainability) dataDear readers & contributers! I am completely new here, a master (Msc. Sustainable Finance) stud…
Fake private messagesIf anyone receives a private message that appears to be from me please disregard it (and perhaps not…
Random group generationDear Statalists, I would like to generate 67 random groups for 271 observations. I know the below c…
Subscribe to:
Post Comments (Atom)
0 Response to Need Help on STATA loop
Post a Comment