Announcement

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

  • First occurrence using egen

    Hi Stata users,

    I am having individual level dataset and would like to use
    Code:
    egen
    command to generate the first occurrence per household
    Below is an example of the data set

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(hhid ind_id value first)
    1 11 2.76 2.76
    1 12 1.44 2.76
    1 13 1.94 2.76
    2 21 3.12 3.12
    2 22 1.87 3.12
    3 31 2.04 2.04
    3 32 3.79 2.04
    3 33 1.65 2.04
    3 34 2.89 2.04
    4 41 1.87 1.87
    5 51 2.04 2.04
    5 52 1.97 2.04
    5 53 1.52 2.04
    end
    The idea is
    Code:
    first
    to be the first value of
    Code:
    value
    per household.

    Thanks in advance!

  • #2
    Stephen:
    do you mean something along teh following line?
    Code:
    bysort hhid: gen wanted=value[1]
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      No need to use egen at all.

      Code:
      bysort hhid (ind_id) : gen wanted = value[1]

      Comment


      • #4
        Thanks a bunch! Carlo Lazzaro Yes, this is my desired goal

        Comment


        • #5
          Nick Cox as always you never disappoint. Thanks so much for your help.

          Comment

          Working...
          X