Announcement

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

  • Matching oberservations with different characteristics

    Dear all,

    I am combining exact and propensity matching using the function kmatch.
    This example code matches male and female patients. First three categories of age are matched using exact matching and then bloodpressure is used for ps-macthing nearest neighbor matching within these age-groups.

    Code:
    sysuse bplong
    keep if when == 1
    kmatch ps sex bp, idgenerate idvar(patient) ematch(agegrp) wor nn(1)
    What I however seek to do is to match units of different age groups. I.e., a unit of age group of 1 should not be exactly match to another unit of age-group 1 (as it is in the example) but to a unit of age-group 2 or 3.

    Could perhaps anyone provide suggestions on how to implement this?




  • #2
    Tricky. I don't think kmatch can do it.

    Here's a brute force. No guarantees. The way you sort the data makes a difference in the matches, but the difference in the PS are trivially small.

    I assume you are treating sex as the treatment for illustration (thanks for the example).

    Code:
    sysuse bplong , clear
    keep if when == 1
    
    ** GET PS 
    pscore sex bp , pscore(PS)
    
    ** CREATE DATA FOR MERGE
    preserve
        rename patient match
        rename agegrp m_agegrp
        rename PS PS_match
        keep match m_agegrp PS_match
        save matchage, replace
    restore
    
    ** CREATE MATCH VARIABLES
    g match = .
    
    ** SORT BY PS
    sort PS
    
    forv i = 1/120 {
        if match==. in `i' {
        summ agegrp in `i'
        local age = r(mean)
        summ PS in `i'
        local ps = r(mean)
        capture drop diff
        g diff = abs(PS - `ps') 
        capture drop rank
        egen rank = rank(diff) if mi(match) & agegrp!=`age' , unique
        summ patient if rank==1
        local pat = r(mean)
        replace match = `pat' in `i' if mi(match)
        summ patient in `i'
        replace match = `r(mean)' if mi(match) & patient==`pat'
        }
    }
    drop diff rank
    
    ** MAKE SURE NO REPLACEMENT
    summ match
    gunique match
    
    ** ADD IN MATCHED PS AND AGE GROUP
    joinby match using matchage , unmatched(master)
    
    ** CHECK AGEGRP NOT EQUAL
    g test = agegrp == m_agegrp
    assert agegrp != m_agegrp
    
    ** GET DIFFERENCE OF PS FOR TRIMMING
    g diff = PS - PS_match  // can replace match ==. by caliper

    Comment

    Working...
    X