Announcement

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

  • Generate new group by id and other group in panel data

    Dear all,
    I know that the title is confusing, but I had no idea how to better describe my issue.
    So, I have the following dataset:
    id group
    1 -1
    1 -1
    1 -1
    2 0
    2 0
    2 0
    3 1
    3 1
    3 1
    3 1
    4 -1
    4 1
    5 -1
    5 0
    I would like to generate a new variable that would take different values, depending on the values from the group variable, per id.
    So, if there are only -1, then the new variable will be 0 (or whatever number) for the respective person (in my example id 1 will have this value). If there are only 0 another number (id 2). If there are only -1 and 0 another number (id 5)... and so on.

    Thank you,
    Dimi



  • #2
    To help us understand your question properly, could you please post your desired final data?
    Please check: https://www.statalist.org/forums/for...econd-variable

    Last edited by Amin Sofla; 23 May 2018, 03:24.

    Comment


    • #3
      Agreeing with Amin's comment, you'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

      Just a guess, but egen g=group(id group) might be what you want.

      Comment

      Working...
      X