Announcement

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

  • Checking the student grades in different semesters (long format)

    Dear All,

    I have a data in a long format (students data with their grades in each semester). I would like to be able to check if the student has the same grades throughout the semesters, or does s/he moves up/down in terms of his grades (for example from 50 in semester 1 to 60 in semester2, .. )

    I have tried to use the following code, to check if the grades are same in all the semesters

    Code:
    by id semester, sort: gen scores = 1 if semester[_n] = semester[_n-1]
    But I am sure its not correct, and not sure how work around it,

    - I was also thinking of reshaping my data into wide format, is the way to go?

    Here is how my data looks:

    Code:
    id semester grade
    1 1 90
    1 2 90
    1 3 90
    1 4 90
    2 1 85
    2 2 .
    2 3 80
    3 1 50
    3 2 60
    3 3 70
    3 4 70
    4 1 95
    4 2 90
    4 3 85
    4 4 80
    Thank in advance for your help.

  • #2
    Are you looking for something like this?

    Code:
    bys id (semester): gen scores = (grade == grade[_n-1])
    Or this?

    Code:
    egen avg = mean(grade), by(id)
    gen  scores = (grade == avg)
    drop avg
    Last edited by Justin Niakamal; 24 Jun 2020, 17:22.

    Comment


    • #3
      Thanks Justin.

      It almost what I was looking for. But I just noticed that I wouldn't be able to report the changes in the grades if it captured in my data as percentage. So, I have updated my data as follow:
      Code:
      id semester grade
      1 1 Excellent
      1 2 Excellent
      1 3 Excellent
      1 4 Excellent
      2 1 Very good
      2 2 .
      2 3 Very good
      3 1 Pass
      3 2 Good
      3 3 Very good
      3 4 Very good
      4 1 Excellent
      4 2 Excellent
      4 3 Very good
      4 4 Very good


      So, what I am looking for is to able to count the number of the students: (1) Their grades never changed (first student with id 1). (2) Students who their grades have changed (from Excellent to Pass, or from Pass to Excellent, ...)

      Hope its clear now.

      Comment


      • #4
        I have reshaped my data into wide format, then I used the "concat" function.

        I think its better, in this case, to handle my question in wide format data.

        Any suggestions?

        Comment


        • #5
          So, what I am looking for is to able to count the number of the students: (1) Their grades never changed (first student with id 1). (2) Students who their grades have changed (from Excellent to Pass, or from Pass to Excellent, ...)

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input byte(id semester) str9 grade
          1 1 "Excellent"
          1 2 "Excellent"
          1 3 "Excellent"
          1 4 "Excellent"
          2 1 "Very good"
          2 2 "."        
          2 3 "Very good"
          3 1 "Pass"     
          3 2 "Good"     
          3 3 "Very good"
          3 4 "Very good"
          4 1 "Excellent"
          4 2 "Excellent"
          4 3 "Very good"
          4 4 "Very good"
          end
          
          bys id (grade): gen wanted1=grade[1]==grade[_N]
          bys id (sem): gen wanted2=grade=="Pass" & grade[_n-1]=="Excellent"|grade=="Excellent" & grade[_n-1]=="Pass"
          bys id (wanted2): replace wanted2=wanted2[_N]
          egen tag= tag(id)
          count if wanted1 & tag
          count if wanted2 & tag
          Res.:

          Code:
          . count if wanted1 & tag
            1
          
          . count if wanted2 & tag
            0

          Comment

          Working...
          X