Announcement

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

  • Combine multiple columns into one

    Hi all,

    If there is a loop like following:

    Code:
    forv y = 2009/2012 {
    forv p = 1/20 {
        egen `y'_`p' = mean(var) if year == `y' & portfolio == `p'
    }
    }
    is there a way to combine `y'_`p' into a single column?

    Thank you.

  • #2
    If I understand this correctly, it would be simpler if there was no such loop in the first place.

    Code:
    bysort year portfolio : egen mean = mean(var)
    Note that `y'_`p' cannot be a valid variable name because both `y' and `p' hold numbers and variable names cannot start with numbers.

    Best
    Daniel

    Comment


    • #3
      ah yes indeed, bys could do the trick..I felt stupid to ask this, thank you Daniel.

      Comment


      • #4
        Originally posted by Yuxi Chen View Post
        I felt stupid to ask this
        Do not. Chances are, you are not the only one having this problem.

        Best
        Daniel

        Comment

        Working...
        X