Announcement

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

  • collapse for student id

    Hello! I have a data set where I have multiple observations for each student, where the personal information is repeated, but the courses information is different in each observation.
    Example:

    student_id name age course teacher_gender
    1 Mike 20 Eco1 F
    1 Mike 20 Mat1 M
    2 Sara 21 Eco1 M
    2 Sara 21 Mat1 F
    3 Sofia 19 Eco1 M
    3 Sofia 19 Arts1 F
    Next, I created 2 dummies,
    gen_eco1=1 if teacher_gender=F and gen_eco1=0 y teacher_gender=M
    mat=0 , replace mat=1 if course=Mat1

    With this, I want to know the students that had a female teacher in Eco1, and the students that later took the course of Mat1 (not all the students have an observation with the course Mat1).

    I don't know how to collapse this information, because both of my dummies are not talking... I think I could use the collapse function but I'm not sure. If anyone could help me I would be very thankful.

    Thanks!




  • #2
    Your question is unclear. In what sense do you want to "know" the students that had a female teacher in Eco1... Do you mean you want to create a variable that indicates them? Do you mean you want to keep them in the data set but drop everybody else? Or the other way around? Or maybe you want to list them? What do you have in mind?

    Next, you cannot from this data discern which students later took the Mat1 course, because there is nothing in this data set that marks the passage of time. (Well, you have age, but in your example data, everybody is the same age for both courses so there is no way to tell if the Mat1 came before or after Eco1.)

    You cannot possibly have run
    Code:
    gen_eco1=1
    if teacher_gender=F
    gen_eco1=0
    y teacher_gender=M

    First, there is no command gen_eco1. Second, assuming you meant -gen eco1 = 1 if ...- the second -gen eco1 = 0 y...- command would fail for several resons. The first reason is that eco1 would already exist, so you cannot -generate it-. You would need to -replace- it. The second reason is that you have "y" where you should have "if". Also, -teacher_gender = M- will also lead to an error message because you have no variable named M, and a single = in that context is also not legal Stata syntax.. Presumably you meant -teacher_gender == "M"-When you are posting commands you have run, it is important to post the exact code that you ran, along with any outputyou got (including error messages). The way to be sure you get that right is to copy directly from your Results window or log file to your computer's clipboard and then paste it here into the Forum editor. Nobody can fix your code if what you show isn't the actual code that needs fixing.

    I also do not know what you mean when you say your "dummies are not talking."

    Here's what I suggest you do. Post your problem again. But this time:

    1. Show example using the -dataex- command.
    If you are running version 16 or a fully updated version 15.1 or 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.

    2. Show the exact code you ran along with the output and any error messages you got.

    3. Based on the example data you post, calculate by hand what the results you want should look like and post those results so we can see where you want to go with this.

    Comment

    Working...
    X