Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • loop

    Dear stata community

    I have a data set that about common analyst followings. In this set i want to repeat this code, gen group1 = roe if connections1>0, when repeated it should be gen group2 = roe if connections2>0 and so forth and so on. I know it has to be done through a loop but i cant manage to pull it off.

    Is there anyone that can help me with this, thank you so much in advance, it would be of great help.

    Kind Regards,

    Barry Opdam

  • #2
    how about:
    Code:
    forval i=1/X {
    gen group`i' = roe if connections`i'>0
    }
    replace X with whatever your largest number is

    note that if you have any missing values in your "connections#" variables they will qualify for the gen command (as missing is considered to be larger than 0 in Stata)
    Last edited by Rich Goldstein; 07 Jun 2018, 06:03.

    Comment

    Working...
    X