Announcement

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

  • creating a variable that assigns the same value for each id

    Hello, I am working with a panel data that has household id (h_id) , individual id (h_pid), age, relationship with the householder and etc. I have attached a screenshot of a part of the dataset.

    I want to specify whether an individual is a child (i have set the age from 0~10) or not.

    So far, I have created a dummy variable to identify the observations with the age 0 or 1 (because some are born in between the survey dates).

    What i want to have is a dummy variable, child1, that assigns 1 to each individual id if he/she is a child. Something like below

    h_id h_pid year age child child1
    693 69352 2015 1 1 1
    693 69352 2016 2 0 1
    693 69352 2017 3 0 1
    693 69352 2018 4 0 1
    693 69352 2019 5 0 1

    Please help me to code this. Thank you.
    Attached Files
    Last edited by Sujin Shin; 19 Apr 2022, 06:23.

  • #2
    g child = inrange(age,0,10)

    Edit: In the future, please do not upload screenshots or manually post data, when showing problems with data, always use the dataex command.
    Last edited by Jared Greathouse; 19 Apr 2022, 06:30.

    Comment


    • #3
      Code:
      bysort h_id: egen child1 = max(child)

      Comment

      Working...
      X