Announcement

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

  • How can I Find the Failed Students in the Data Set in Stata?

    I have a small dataset as follows, and I want to identify the students who failed the exam. If the student failed, then fail==1, otherwise, fail==0.
    The new variable to be created is called F (F=1, suggesting a student failed in the exam).


    * Example generated by -dataex-.
    clear
    input byte (sid fail)
    1 0
    1 0
    1 0
    1 1
    2 1
    2 0
    2 0
    2 0
    3 0
    3 0
    3 0
    3 0
    4 0
    4 0
    4 1
    end

    Thank you for your Stata code!
    Last edited by smith Jason; 16 Jul 2022, 13:15.

  • #2
    I don't think I fully understand, but the following appears to do what I think you are asking for:
    Code:
    egen byte F=max(fail), by(sid)

    Comment


    • #3
      Thank you!

      Comment


      • #4
        bys sid: egen F=max(fail) works as well.

        Comment


        • #5
          Originally posted by smith Jason View Post
          bys sid: egen F=max(fail) works as well.
          These are (almost) equivalent syntaxes. The -egen- functions can be used both as

          Code:
          bysort sid: egen F=max(fail)
          and as

          Code:
          egen F=max(fail), by(sid)

          Comment


          • #6
            Thank you!

            Comment

            Working...
            X