Announcement

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

  • Matched datasets


    I am using the code below for the nearest matching but I am struggling with obtaining a matched dataset for further analyses. I used the following commands but it did not work. Can anyone please help me?

    teffects nnmatch (DV IVs) (treatment_variable), generate (newvar)

    gen obsnum = _n
    keep newvar*
    stack newvar*, into(obsnum) clear
    drop _stack
    bysort obsnum: keep if (_n == 1)
    gen byte in_sample = 1
    tempfile matchsample
    save `matchsample'
    Last edited by April Kimm; 04 Mar 2022, 12:02.

  • #2
    this works for me,
    Code:
    webuse cattaneo2, clear
    
    gen obsnum = _n
    
    preserve
    teffects nnmatch (bweight mage prenatal1 mmarried fbaby) (mbsmoke), gen(newvar)
    stack newvar*, into(obsnum) clear
    bys obsnum: keep if _n==1
    tempfile matched
    save `matched'
    restore
    
    merge 1:1 obsnum using `matched', keepus(obsnum)
    matched sample are observations with -_merge==3-

    Comment


    • #3
      Thank you! It worked well.

      Comment

      Working...
      X