Announcement

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

  • Survey pointer to spouse without Mata

    I'm using the IPUMS extract of the CPS March Supplement. In their extract, the variables YEAR, SERIAL, and PERNUM together uniquely identify person records in each annual sample.

    They also include a variable, SPLOC, that gives the PERNUM value of the person's spouse.

    I would like to create a variable called SPEMPSTAT that gives the labor market status (EMPSTAT) of each person's spouse (if they have one). In other words, use the combination of YEAR, SERIAL, and SPLOC in the person's record as a pointer to another record's YEAR, SERIAL, and PERNUM combination.

    I've seen some mention that this is possible with Mata, but I wanted to make sure there wasn't a way of doing this within Stata.



  • #2
    It doesn't sound like you need a pointer. Presumably there is already a variable, let's say it's called EMPSTAT, that provides the employment status of each person. Then to get the SPEMPSTAT all you need is:

    Code:
    isid YEAR SERIAL PERMNUM, sort
    rangestat (mean) SPEMPSTAT = EMPSTAT, by(YEAR SERIAL) interval(PERMNUM SPLOC SPLOC)
    -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer. It is available from SSC.

    (Note: Not tested as no example data was shown. Also, this code will only work if PERMNUM, SPLOC, and EMPSTAT are all numeric variables.)

    Comment


    • #3
      Here's another approach, using the built-in -merge-. Also not tested.
      Code:
      use YourData
      // Make file with potential spouses, with SPLOC as the key
      preserve
      rename PERNUM SPLOC
      rename EMPSTAT SPEMPSTAT
      tempfile spouse
      save `spouse'
      restore
      //  Get employment status from anyone in the spouse file that matches an SPLOC in the master file.
      merge 1:1 SPLOC using `spouse', keepusing(SPEMPSTAT)
      tab _merge
      keep if inlist(_merge, 1,3)

      Comment


      • #4
        The rangestat package worked perfectly. Thank you!

        Comment

        Working...
        X