Announcement

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

  • Isolate matched sample when using psmatch2 with kernel option

    Dear forum, I am struggling with how to perform a propensity score matching analysis using the kernel option instead of nearest neighbor one. My aim is to first do the psmatch2 over the treatment, and then over the matched sample I do the main panel data analysis. However, I do not know how to capture the matched sample when using kernel option. Below you will see the code I am using with the nearest neighbor option. Notice that what I obtain is not only the sample of matched obs, but instead, of matched firms (matchedsample_firm).

    Can you please help me to obtain the similar analysis but with the kernel matching?

    Thanks for your help!

    Code:
    psmatch2 treatment, pscore(pscore2) outcome(y) neighbor(2) caliper(0.2) logit common 
    
    gen pair = _id if _treated==0  
    replace pair = _n1 if _treated==1
    bysort pair: egen paircount = count(pair)
    tab paircount
    gen _matchedsample1to1 =(paircount==2 | paircount==3 | paircount==4 | paircount==5 | paircount==6)
    tab _matchedsample1to1
    
    gen pair2 = _id if _treated==0  
    replace pair2 = _n2 if _treated==1
    bysort pair2: egen paircount_n2 = count(pair2)
    tab paircount_n2
    gen _matchedsample1to1_n2 =(paircount_n2==2 | paircount_n2==3 | paircount_n2==4 | paircount_n2==5 | paircount_n2==6)
    tab _matchedsample1to1_n2
    
    cap drop matchcell maxms mismatch_csy 
    
    cap drop max_* 
    bys pair: egen max_sec2=max(sector)
    replace max_sec2=. if pair==. 
    bys pair2: egen max_sec2_n2=max(sector)
    replace max_sec2_n2=. if  pair2==.
      bys pair: egen max_year=max(year)
      replace max_year=. if pair==.
      bys pair2: egen max_year_n2=max(year)
      replace max_year_n2=. if pair2==.
    
    
    cap drop wrong_match* 
    cap drop mismatch_csy*
    gen wrong_match=((sector!=max_sec2 | year!=max_year) & _matchedsample1to1==1)
    gen wrong_match_n2=((sector!=max_sec2_n2 | year!=max_year_n2) & _matchedsample1to1_n2==1)
    compress
    
    bys pair: egen byte mismatch_csy = max(wrong_match)
    bys pair2: egen byte mismatch_csy_n2 = max(wrong_match_n2)
    
    
    gen _matchedsample = ( _matchedsample1to1 | _matchedsample1to1_n2 )
    tab _matchedsample
    
    *Eliminate the possible mismatches
    drop if mismatch_csy==1
    drop if mismatch_csy_n2==1
    drop wrong_match*
    drop mismatch_csy*
    drop max_*
    
    *_matchedsample==1 identifies the firm-years (obs), not entire firm.
    cap drop matchedsample_firm
    bys ident: egen matchedsample_firm = max(_matchedsample)
    keep if matchedsample_firm==1
Working...
X