Announcement

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

  • Matching exactly on group and closest on other variables (with psmatch2)

    Hi,

    I am trying to use psmatch2 to match exactly on industry code (sic2) and year (cyear). I have read the psmatch2 help guide and all other matching threads on this forum, but cannot find a solution to my problem.

    My code looks like this (copied almost identically from the psmatch2 guide but with my variables):

    Code:
            g att = .
            egen g = group(sic2 cyear)
            levels g, local(gr)
            qui foreach j of local gr {
                    psmatch2 treat_firm firm_size if g==`j', out(roa_w1)
                    replace att = r(att) if  g==`j'
            }
    sic2 = my industry codes. there are about 1000 observations in each industry for each year

    treat_firm = 1 for treated firms and 0 for all potential control match firms

    firm_size = continuous matching variable indicating firm size

    The code seems to run, but then doesn't finish. Stops running with this output:

    Code:
    .         g att = .
    (251,679 missing values generated)
    
    .         egen g = group(sic2)
    
    .         levels g, local(gr)
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    >  71 72 73
    
    .         qui foreach j of local gr {
    r(2000);
    No new variables are created that are supposed to come from psmatch2 (e.g., _id). Any help would be greatly appreciated. Thank you!

    Roger

  • #2
    Follow up: I discovered a solution when I add capture before the psmatch2 line of code, to read:

    Code:
     
                   g att = .         egen g = group(sic2 cyear)          levels g, local(gr)         qui foreach j of local gr {                 capture psmatch2 treat_firm firm_size if g==`j', out(roa_w1)                 replace att = r(att) if  g==`j'         }
    I read the help file on capture and see it suppresses errors. Should I be concerned that the code worked with "capture" but not without "capture"? The output seems as I would expect...

    Comment

    Working...
    X