Announcement

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

  • Matching with propensity score matching in a panel data

    Hello,

    I am studying the effect of being a neighbor to a person who retrofitted their home "treated==1".

    I have a huge control group but I want to match a smaller control group on the following seperately :
    1- pre-treatment consumption "annual_gas_m3"
    2- House characteristics "lotsize_N buildingsize_N totalassessmentvalue_N effectiveyearbuild_N bld_cond_N_dummy bldg_type_N_dummy umlocclass_N_dummy"
    3- Pre-treatment consumption and house characteristics (1 and 2)

    For my analysis with the whole control group I am using TWFE:
    reghdfe log_gas_m3 treated_post if neighbour<4 &sample1==1 , absorb(ID cons_cal_month) vce (cluster double_cluster)

    Thank you

    (Note that the subset of data below doesn't show the variation in the treatment but I have a huge dataset with more than 20,000 houses)


    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long ID float log_gas_m3 int cons_date float(treated treated_post lotsize_N buildingsize_N) long totalassessmentvalue_N int effectiveyearbuild_N long(bld_cond_N_dummy bldg_type_N_dummy umlocclass_N_dummy)
    500003 6.621079 17167 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.82175 17198 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.93616 17226 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.269681 17257 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.503296 17287 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 . 17318 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.117002 17348 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.033292 17379 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 . 17410 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.269681 17440 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.726439 17471 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 . 17501 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 7.644094 17532 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 . 17563 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 7.040178 17592 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.417648 17623 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.034656 17653 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.724501 17684 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.099195 17714 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 . 17745 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.406047 17776 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.371128 17806 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 . 17837 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.4621 17867 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 7.733325 17898 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.792342 17929 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.584702 17957 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.965663 17988 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.629191 18018 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.52383 18049 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.272516 18079 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.272516 18110 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.272516 18141 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.159819 18171 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.216978 18202 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 7.155247 18232 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 7.216523 18263 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.889651 18294 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.157916 18322 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.889651 18353 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.889651 18383 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.521927 18414 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.521927 18444 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.116462 18475 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.116462 18506 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.521927 18536 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.269141 18567 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 7.108892 18597 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.937788 18628 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.882218 18659 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.760857 18687 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.724765 18718 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.406312 18748 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.406312 18779 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.27278 18809 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.118629 18840 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.118629 18871 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.629455 18901 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.417912 18932 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.588215 18962 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.731316 18993 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.662323 19024 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.102707 19053 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.527343 19084 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.276029 19114 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 4.7164125 19145 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.728014 19175 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 4.939556 19206 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 4.939556 19237 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.728014 19267 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.731316 19298 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.625955 19328 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 7.009774 19359 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.616731 19390 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.265333 19418 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.885844 19449 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.518119 19479 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.518119 19510 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.400336 19540 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.112654 19571 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.266804 19602 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.028944 19632 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.959951 19663 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.847255 19693 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.503591 19724 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 7.086738 19755 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.32127 19783 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.628122 19814 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.404979 19844 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.404979 19875 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.271448 19905 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.117297 19936 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.271448 19967 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.404979 19997 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.41658 20028 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.822045 20058 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.658444 20089 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.658444 20120 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 6.216611 20148 0 0 1551.48 343.3 794100 1991 2 23 14
    500003 5.523464 20179 0 0 1551.48 343.3 794100 1991 2 23 14
    end
    format %td cons_date
    label values bld_cond_N_dummy bld_cond_N_dummy
    label def bld_cond_N_dummy 2 "AVERAGE", modify
    label values bldg_type_N_dummy bldg_type_N_dummy
    label def bldg_type_N_dummy 23 "2STYBSMT", modify
    label values umlocclass_N_dummy umlocclass_N_dummy
    label def umlocclass_N_dummy 14 "RESIDENTIAL", modify
    [/CODE]

  • #2
    I tried this code from the forum and tried to match on "effectiveyearbuild_N", but I get the error "effectiveyearbuild_N_ctrl not found".
    Any help?


    // CREATE A FILE OF JUST CONTROLS
    // AND RENAME THE VARIABLES
    preserve
    keep if treated == 0
    ds effectiveyearbuild_N , not
    rename (`r(varlist)') =_ctrl
    tempfile controls
    save `controls'

    // BRING BACK THE DATA & KEEP ONLY CASES
    restore
    keep if treated == 1

    // UNIQUELY IDENTIFY EACH OBSERVATION
    gen long obs_no = _n

    // MATCH EXACTLY ON
    joinby effectiveyearbuild_N using `controls'
    drop if missing(ID_ctrl)

    // RETAIN THE BEST MATCH ON effectiveyearbuilt_N
    gen delta = abs(effectiveyearbuild_N-effectiveyearbuild_N_ctrl)
    set seed 1234 // OR YOUR FAVORITE SEED NUMBER
    gen double shuffle1 = runiform()
    gen double shuffle2 = runiform()
    by obs_no (delta shuffle1 shuffle2), sort: keep if _n == 1

    Comment

    Working...
    X