Announcement

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

  • Merging single variables of panel data into the master file

    I am trying to merge certain variables from different files into the master data file. I have 9 waves of panel data each corresponding to a different year in each of 4 different stata files. Each stata file contains the same individuals over the same years. The problem as it is very common is that certain variables of interest are located in different files, (ie different surveys done of the same individuals are put into different files) thus in order to run my regression I need other variables for the same individuals not located in the master file. For example: in measuring the effect of education on wages I have the wage and education variables in my master data but I need to include the gender variable located in a different file. Both files have the same waves(same years) and same(almost) individuals.

    When I run :

    merge 1:1 gender2008 using dataset.dta

    I keep getting an error 111 where the gender2008 or any other variable I try for that matter is not found.

    Any suggestions?
    Thanks in advance

  • #2
    George:
    the most trivial reason is a different name of the variables you're trying to merge.
    I would also check for the existence of leading or trailing blanks, especially if you have imported your file from a spreadsheet format.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thanks for the fast reply, no the file was not imported from a spreadsheet format. How is it possible to merge then an additional variable into my master dataset containing the same individuals for the same years? The variable gender does not exist in my master dataset.
      Thank you!

      Comment


      • #4
        If gender2008 is the variable you are trying to add to your master file, then you have interpreted the syntax of the merge command incorrectly. The variables you list after "1:1" are the variables common to both files (individual identifier, year) that are used to match corresponding observations together. You perhaps need something like
        Code:
        merge 1:1 individual year using dataset.dta, keepusing(gender2008)
        but of course this is not tested. Do see the full documentation of the merge command in the Stata Data Management Reference Manual PDF included in your Stata installation and accessible through the Stata Help menu.

        Comment

        Working...
        X