Announcement

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

  • Questions on finding the lowest value amongst different variables

    Dear all,

    First of all, Happy New Year!


    I have a question on generating a variable that gives a value that is lowest amongst several variables.

    So I have a couple data and need to create a variable that shows the youngest age of children.

    The age of children is coded as "age_household member1", "age_household member2", "age_household member3"...

    For example, if a father has three children, then their ages are coded like this:
    "age_household member1" = 10
    "age_household member2" = 12
    "age_household member3" = 14

    With these information, I need to generate a "youngest age of child" variable. In that case, the value of this variable would be 10.
    It takes lots of steps to generate this variable with the codes I know. I would like to ask you if you know a simpler and better way to generate this variable.


    Thank you very much in advance for your assistance..!

  • #2
    Code:
    egen minage = rowmin(age_household_member1 age_household_member2 age_household_member3)
    Best wishes

    (Stata 16.1 MP)

    Comment


    • #3
      Felix Bittmann gave excellent advice. Note that the function

      Code:
      min()
      offers another approach.

      Details:

      Code:
      gen wanted = min(age_household member1, age_household member2, age_household member3)
      Last edited by Nick Cox; 02 Jan 2025, 05:48.

      Comment

      Working...
      X