Announcement

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

  • Confusion about how to keep students in the right courses in the right level

    Stata 15.1
    I have a list of students who are taking certain courses. Some of the courses have level 1, 2, 3, or 4. Right now, if a student is in a course that has more than 1 level, it appears that they have taken that course many times when it should only show up once. I want to put them in the right course and level.

    Example 1:
    Variables: Student, course, level
    Student A, course 2000, level 1
    Student A, course 3000, level 1
    Student A, course 3000, level 2
    Student A, course 3000, level 3
    Student A, course 3000, level 4
    Student A, course 4000, level 2

    I would like my final data set to look like this:

    Student A, course 2000, level 1
    Student A, course 3000, level 3
    Student A, course 4000, level 2

    Example 2:
    Variables: Student, course, level
    Student B, course 3000, level 1
    Student B, course 3000, level 2
    Student B, course 3000, level 3
    Student B, course 3000, level 4
    Student B, course 4000, level 3

    I would like my final data set to look like this:

    Student B, course 3000, level 1
    Student B, course 4000, level 3

    Should I be using bysort, egen command? What command is there for sequencing or ordering of observations by course and level? Any guidance would be great!

  • #2
    I don't understand what you want to do. In your first example, I understand why you want to end up with

    Code:
    Student A, course 2000, level 1
    
    Student A, course 4000, level 2
    But for course 3000, what is the rule you are using that leads you to keep level 3 as opposed to any of the other levels? I could understand the choice of level 1 or level 4 (the lowest or highest) but I do not grasp how you arrived at level 3. Example 2 seems to suggest you want to keep just the lowest level--but that is inconsistent with choosing level 3 for course 3000 in example 1.

    Please clarify.

    Also, if you would like help with code, rather than just brief general advice, please include an actual example of your Stata dataset, using the -dataex- command to do so. If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.



    When asking for help with code, always show example data. When showing example data, always use -dataex-

    Comment


    • #3
      Thank you for your response. The problem with this data is that there is a lot of flexibility in the courses students could take across programs of study. They could take a course that could count as a level 3 or 4 and sometimes even level 2. The purpose of this is to identify how many students took any 2 courses, any 2 courses in sequence, any 2 level 2/3/4 (higher level) courses in sequence, and any 2 level 2/3/4 courses not in sequence. For sequence, I'm not worried about school year as students sometimes take a level 4 course before a level 3 and I want to count these courses.

      For example 1, the student took 3 courses only, but course 3000 could be a level 1, 2, 3, or 4 course. Course 3000 shows up 4 times, because of this. Right now, the results I calculated show that the student took 6 courses when they only took 3. Since the student already took a level 1 and 2 course, I chose for course 3000 to be a level 3 course (choosing the lower level course). It's complex. In a program of study, students are encouraged to take a level 1 course, then a level 2, 3, and so on.

      I'm not sure how you displayed the code in the text box.

      code example using dataex:
      input double(grad_year schoolyear studentkey) int coursecode str47 program_of_study byte level
      2018 2014 1234 5957 "Agriculture, Food, & Natural Resources" 1
      2018 2016 1234 4269 "Agriculture, Food, & Natural Resources" 3
      2018 2015 1234 6073 "Architecture & Construction" 1
      2018 2016 1234 4062 "Advanced Manufacturing" 4
      2018 2017 1234 4062 "Advanced Manufacturing" 3

      I changed studentkey to 1234 for privacy.

      In this case, I would like my final data set to look like this:
      2018 2014 1234 5957 "Agriculture, Food, & Natural Resources" 1
      2018 2015 1234 6073 "Architecture & Construction" 1
      2018 2016 1234 4269 "Agriculture, Food, & Natural Resources" 3
      2018 2016 1234 4062 "Advanced Manufacturing" 4

      I included both level 1 courses, because the student took those courses and they need to be counted. For course 4062, the student took that course once but it can be a level 3 or 4. Right now, it's showing that he/she took 4062 twice. Since the student already took a level 3 course (course 4269), I would like for 4062 to be a level 4 course in this case.
      Last edited by sladmin; 16 Nov 2020, 14:42. Reason: anonymize original poster

      Comment


      • #4
        I'm sorry, but I really don't understand this.

        Comment


        • #5
          I agree with Clyde that your description is not clear. However, it appears that you want to drop duplicates defined in terms of two conditions. If so, the following may be what you want.

          Code:
          duplicates tag studentkey coursecode program_of_study, gen(dup1)
          duplicates tag studentkey level, gen(dup2)
          drop if dup1& dup2
          ADDED IN EDIT: Before running the code, confirm that the following variables uniquely identify your observations. If not, sort this out first.

          Code:
          isid studentkey coursecode program_of_study level
          Last edited by Andrew Musau; 13 May 2019, 17:23.

          Comment

          Working...
          X