Announcement

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

  • Create a Binary Variable that Indicate if a student was Retained in Grades in a Long Format Dataset.

    I have a small dataset, which is layout in long format.
    What I want is to create a new variable "retain" with the rules as follows,
    as long as there is a "1" on the state variable within id, then the value of retain should be equal to 1 within id.
    if all values of state variable within id =0, then then the value of retain should be equal to 0 within id.
    if all values of state variable within id =1, then then the value of retain should be equal to 1 within id.
    Can someone help me to do this with Stata code?
    Thank you!


    clear
    input str10 id byte (grade state)
    1 1 0
    1 2 0
    1 3 0
    2 1 0
    2 1 1
    2 2 0
    3 1 0
    3 2 0
    3 2 1
    4 1 0
    4 2 0
    4 2 1
    4 3 0
    end

  • #2
    Code:
    bys id: egen byte retain = max(state)
    this assumes that state is binary.

    Comment


    • #3
      Originally posted by Hemanshu Kumar View Post
      Code:
      bys id: egen byte retain = max(state)
      this assumes that state is binary.
      Thank you!

      Comment


      • #4
        For more discussion if needed

        https://www.stata.com/support/faqs/d...ble-recording/

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Thank you for your resources!

          Comment

          Working...
          X