Announcement

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

  • Merge two data sets with unit observations from data set A not data set B.

    Hello, I'm new to Stata and please help. I have a question about merging two data sets.
    In data set A, I have a variable Students with 5 observations and some other variables.
    In data set B, I have a variable Groups with 3 observations and some other variables.
    One feature of those two data sets is that the 5 students can fall into the 3 groups.

    Now I want to merge data sets A and B with a common variable, what I get from the result is now I have a combined data set with 5 observations for both students and groups. What Stata did for me is generating 2 more duplicated groups for me.

    The question is I want to make Group the unique observations because I want to do a regression with variable Group not Students.In other words, I want to generate another variable NumberofStudentsWithinEachClass.
    Can anyone help me with the merge and generating the variable? Thank you very much guys.

    Alex

  • #2
    This kind of problem is easier to understand if you show excerpts from you data. Please also show the commands that you used. Please read section 12 in the FAQ for more detailed advice on asking questions on Statalist.

    Comment


    • #3
      Originally posted by Friedrich Huebler View Post
      This kind of problem is easier to understand if you show excerpts from you data. Please also show the commands that you used. Please read section 12 in the FAQ for more detailed advice on asking questions on Statalist.
      dbmerge is the command that I use. I'm simply trying to combine two data sets.

      Here is what my merged data looks like:

      Group1 Student1
      Group1 Student2
      Group2 Student3
      Group3 Student4
      Group3 Student5

      But when I'm running regression on Group, it's not unique observations. So I guess my question is how do I generate a new variable that subtotals the numbers of students within each group so I can have 3 unique observations of Group not 5.

      Thank you very much Friedrich

      Comment


      • #4
        So you have the merged dataset already? Then the problem youre addressing now can be done with collapse. See http://www.stata.com/manuals13/dcollapse.pdf

        Also, you quote Friedrich asking you to rad section 12 of the FAQ, but you havent, and you really should. There's tips in there for more effective posting, including the use of datex for data examples.

        Comment

        Working...
        X