Announcement

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

  • merge problem: observations are matched but I get 'no observations' for variables of interest

    Greetings,

    I'm running Stata 15.1 on OSX. I'm working with a cumulative longitudinal dataset (the American National Election Studies 1948-2016 datafile). It includes a variable measuring household internet for the years 1996-2008. I'd like to merge these data for the years 2012 and 2016 from the individual cross-sectional datasets using the common caseids. I thus created two 'merge' datasets containing the desired variables. I then sorted all datasets by caseid and year. When I ran the merge....:

    Code:
    merge 1:1 caseid year using "/Users/zachgoldberg/Documents/anes12-internetvars.dta"
    ...it indicated a match (merge=3) for all but one of the observations:
    90C7CB4E-D689-4429-AED4-69FD04365953.jpg
    When I tabulate the supposedly merged variable, however...:
    Code:
    tab netaccess
    ...I get 'no observations'.

    Can anyone tell me why this might be/is happening? Thank you for your time!



  • #2
    Not so. Look again at your image: most observations are unmatched.

    I think you’re saying that one file has data until 2008 and the other has data for 2012 and 2016. So neither will match the other.

    There could be lots of other problems here, but without more details on the datasets it’s hard for me to say more.

    Comment


    • #3
      Hey Nick,

      The observations from the 2012 dataset (N=(5,914) are being matched (save for 1). The master dataset has a caseid variable that spans observations across each survey year. Hence, the merged observations from 2012 will only match with the 2012 caseids in the master data.

      I wanted to provide sample data, but wasn't sure whether to provide samples of one or both. I'll go with the latter:

      Here's a sample of the master data (the cumulative 1948-2016 file):
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(year caseid netaccess campnet)
      1996 3024 0 0
      1996 1408 0 0
      1996 3234 1 1
      1996 1422 1 0
      1996 1939 0 0
      1996 1841 0 0
      1996 1397 1 1
      1996 1593 1 0
      1996 3351 0 0
      1996 1206 0 0
      1996 1070 0 0
      1996 2278 1 0
      1996 1940 0 0
      1996 1364 0 0
      1996 1554 0 0
      1996 1662 0 0
      1996 3191 0 0
      1996 1080 0 0
      1996 2169 1 1
      1996 1131 0 0
      1996 1221 0 0
      1996 1584 0 0
      1996 3063 0 0
      1996 2222 0 0
      1996 1952 0 0
      1996 1265 0 0
      1996 2135 0 0
      1996 1506 1 0
      1996 3238 1 0
      1996 1311 1 0
      1996 2009 0 0
      1996 1042 0 0
      1996 1388 1 0
      1996 2029 0 0
      1996 1915 1 0
      1996 1882 1 1
      1996 2098 0 0
      1996 1312 0 0
      1996 3355 1 0
      1996 1099 0 0
      1996 3014 0 0
      1996 1633 0 0
      1996 1673 0 0
      1996 1541 0 0
      1996 1150 0 0
      1996 1053 0 0
      1996 2084 0 0
      1996 3058 0 0
      1996 3157 1 0
      1996 1995 0 0
      1996 1091 0 0
      1996 1200 0 0
      1996 1563 0 0
      1996 1576 0 0
      1996 1569 0 0
      1996 3082 0 0
      1996 2043 0 0
      1996 1831 0 0
      1996 1038 0 0
      1996 1372 0 0
      1996 3023 0 0
      1996 1566 0 0
      1996 3052 0 0
      1996 1401 0 0
      1996 1991 0 0
      1996 3195 0 0
      1996 2259 0 0
      1996 1619 0 0
      1996 3083 0 0
      1996 2091 0 0
      1996 3041 0 0
      1996 3396 0 0
      1996 2027 0 0
      1996 1197 0 0
      1996 1765 0 0
      1996 1964 0 0
      1996 1522 0 0
      1996 3150 0 0
      1996 1086 0 0
      1996 2266 0 0
      1996 3294 1 0
      1996 1225 0 0
      1996 1624 0 0
      1996 1065 0 0
      1996 1845 0 0
      1996 1048 1 0
      1996 1546 0 0
      1996 1392 0 0
      1996 1585 0 0
      1996 1407 0 0
      1996 2069 1 1
      1996 1992 0 0
      1996 1744 0 0
      1996 2227 0 0
      1996 2283 0 0
      1996 2003 1 0
      1996 1016 0 0
      1996 3221 0 0
      1996 1519 0 0
      1996 2115 0 0
      end
      Here's sample data for the master file just for the year 2012 (note the observations for netaccess and campnet are missing as I need to merge them from the individual 2012 cross-sectional file):

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(year caseid netaccess campnet)
      2012   1 . .
      2012   2 . .
      2012   3 . .
      2012   4 . .
      2012   5 . .
      2012   6 . .
      2012   7 . .
      2012   8 . .
      2012   9 . .
      2012  10 . .
      2012  11 . .
      2012  12 . .
      2012  13 . .
      2012  14 . .
      2012  15 . .
      2012  16 . .
      2012  17 . .
      2012  18 . .
      2012  19 . .
      2012  20 . .
      2012  21 . .
      2012  22 . .
      2012  23 . .
      2012  24 . .
      2012  25 . .
      2012  26 . .
      2012  27 . .
      2012  28 . .
      2012  29 . .
      2012  30 . .
      2012  31 . .
      2012  32 . .
      2012  33 . .
      2012  34 . .
      2012  35 . .
      2012  36 . .
      2012  37 . .
      2012  38 . .
      2012  39 . .
      2012  40 . .
      2012  41 . .
      2012  42 . .
      2012  43 . .
      2012  44 . .
      2012  45 . .
      2012  46 . .
      2012  47 . .
      2012  48 . .
      2012  49 . .
      2012  50 . .
      2012  51 . .
      2012  52 . .
      2012  53 . .
      2012  54 . .
      2012  55 . .
      2012  56 . .
      2012  57 . .
      2012  58 . .
      2012  59 . .
      2012  60 . .
      2012  61 . .
      2012  62 . .
      2012  63 . .
      2012  64 . .
      2012  65 . .
      2012  66 . .
      2012  67 . .
      2012  68 . .
      2012  69 . .
      2012  70 . .
      2012  71 . .
      2012  72 . .
      2012  73 . .
      2012  74 . .
      2012  75 . .
      2012  76 . .
      2012  77 . .
      2012  78 . .
      2012  79 . .
      2012  80 . .
      2012  81 . .
      2012  82 . .
      2012  83 . .
      2012  84 . .
      2012  85 . .
      2012  86 . .
      2012  87 . .
      2012  88 . .
      2012  89 . .
      2012  90 . .
      2012  91 . .
      2012  92 . .
      2012  93 . .
      2012  94 . .
      2012  95 . .
      2012  96 . .
      2012  97 . .
      2012  98 . .
      2012  99 . .
      2012 100 . .
      end

      And here's sample data for the 'using' file (for the year 2012):

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(year caseid netaccess campnet)
      2012   1 0 .
      2012   2 0 0
      2012   3 0 0
      2012   4 0 0
      2012   5 1 1
      2012   6 0 0
      2012   7 1 0
      2012   8 0 0
      2012   9 1 0
      2012  10 1 1
      2012  11 1 0
      2012  12 1 0
      2012  13 1 1
      2012  14 1 0
      2012  15 1 0
      2012  16 1 0
      2012  17 1 1
      2012  18 1 0
      2012  19 1 0
      2012  20 1 1
      2012  21 1 1
      2012  22 1 0
      2012  23 1 0
      2012  24 1 .
      2012  25 0 0
      2012  26 1 .
      2012  27 1 0
      2012  28 0 0
      2012  29 1 0
      2012  30 1 1
      2012  31 1 1
      2012  32 1 0
      2012  33 0 0
      2012  34 1 0
      2012  35 0 0
      2012  36 1 0
      2012  37 1 1
      2012  38 1 1
      2012  39 1 1
      2012  40 0 0
      2012  41 1 1
      2012  42 1 1
      2012  43 1 1
      2012  44 1 0
      2012  45 1 1
      2012  46 1 1
      2012  47 1 1
      2012  48 1 1
      2012  49 1 1
      2012  50 1 1
      2012  51 1 1
      2012  52 1 0
      2012  53 1 1
      2012  54 1 0
      2012  55 1 1
      2012  56 1 0
      2012  57 1 1
      2012  58 1 0
      2012  59 1 0
      2012  60 1 0
      2012  61 1 1
      2012  62 1 0
      2012  63 1 1
      2012  64 1 1
      2012  65 1 0
      2012  66 1 0
      2012  67 1 0
      2012  68 1 1
      2012  69 1 0
      2012  70 0 0
      2012  71 1 1
      2012  72 1 1
      2012  73 1 1
      2012  74 1 0
      2012  75 1 1
      2012  76 1 0
      2012  77 1 1
      2012  78 1 0
      2012  79 1 0
      2012  80 1 0
      2012  81 1 1
      2012  82 1 .
      2012  83 1 1
      2012  84 0 0
      2012  85 1 0
      2012  86 1 0
      2012  87 1 1
      2012  88 0 0
      2012  89 1 1
      2012  90 1 0
      2012  91 1 1
      2012  92 1 1
      2012  93 1 .
      2012  94 1 0
      2012  95 0 0
      2012  96 1 1
      2012  97 1 1
      2012  98 1 1
      2012  99 1 0
      2012 100 1 1
      end
      Thanks again for taking the time to help!

      Comment

      Working...
      X