Announcement

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

  • Adding partner data to responding person data in a panel data file

    I wish to extend my analysis of panel data to include information about the responding person's partner so I began the process of merging this extra data to my original (Responding Person) data file. The variables of interest are the same (e.g. age, sex, educ, inc, emp, ...). I collect the data from two separate data files of the HILDA survey. I collect the 'Responding person' data from the "Combined" data file (I think this is correct) and the 'Partner' data from the 'Rperson' data file (where I run a loop to append selected vars for all waves). I believe the 'unique identifier' is xwaveid (destringed), which I obtain for the responding person data. Based on HILDA suggested code (https://melbourneinstitute.unimelb.e...rogram-library) I use the 'unique identifier' hhpxid for the partner data and then rename to xwaveid. There are about 300,000 obs in the responding person data and about 150,000 obs for the partner data. When I merged these two data files it showed I had only about 150,000 obs, which appears as though I have unintentionally deleted all non-partnered 'responding person' obs. I want information on all responding persons and about those with partners. I would appreciate assistance with the code to ensure I am not unintentionally deleting obs from the new data file. My code follows:

    Code:
    clear all
    set memory 1g
    set maxvar 32000 
    set more off
    
    // Merge 'rperson' file with 'partner' file
    
    use "C:\data\rpersondata.dta", clear         
    merge 1:m id wave using "C:\data\partnerdata.dta"                 
    
    order id wave
    sort  id wave
    tsset id wave
    
    save "C:\data\rperson-partner", replace
    .

    I appreciate any help with the process and data.

  • #2
    The code you have given us did not result in you deleting the respondents without partners. So maybe you did something before or after that resulted in deleting those individuals.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you Maarten Buis. The code above was to merge the rperson (responding person) data over 17 waves and the partner data over 17 waves - both of which I appended separately. However, I have since attempted to do this in one do.file. I save the partner data, then the rperson data in a single wave, then merge them together. My issue is how can I run a loop to run this for all waves, appending each wave? My code follows:

      Code:
      log using `logdatadir'/couples.log, replace
      
      local wave a b c d e f g h i j k l m n o p q // all 17 waves
      foreach x of local wave {
      
      use "c:\Combined_`x'170c.dta", clear 
      rename `x'* p_*                // partner data
      rename xwaveid hhpxid
      
      sort hhpxid
      save `writedatadir'/temp, replace
      
      use "c:\Combined_`x'170c.dta", clear 
      rename `x'* *                 // responding person data
      drop if hhpxid==""
      sort hhpxid
      
      merge 1:1 hhpxid using `writedatadir'/temp, replace
      
      append using `readdatadir'/Combined_`x'170c.dta, clear  
      save `writedatadir'/temp, replace   
      }
      
      keep xwaveid hhpxid age sex empl educ wage mrcurr relb relimp relat ///
      p_age p_sex p_empl p_educ p_wage p_mrcurr p_relb p_relimp p_relat // vars of interest
      
      save "`newdatadir'\partner_rperson.dta", replace emptyok //
      Or do I create the loop after I merge the rperson and partner data for wave 1?

      Help appreciated.

      Comment

      Working...
      X