Announcement

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

  • create loop for discrete variable, panel data

    Dear all,
    I am new to stata and I can't figure out how to create a loop for the following code. This problem seems to be recurring in various forms in my descriptive statistics, so any help is greatly appreciated.

    var1 is discrete (5 values)
    var2 is continuous
    var3 is discrete (3 values)

    My code:

    bysort var1: xtsum var2 if var3==1
    bysort var1: xtsum var2 if var3==2
    bysort var1: xtsum var2 if var3==3

    I am now looking for loops to make this code more efficient.

    Sorry for this basic question!
    Cheers,
    Katharina

  • #2
    Look at what changes across your commands and then formulate the loop.

    Code:
    forval i=1/3{
    bysort var1: xtsum var2 if var3==`i'
    }

    Comment

    Working...
    X