Announcement

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

  • Complicated coarsed exact matching

    Hi STATLIST,

    I am stocked into a matching problem. In particular, I would like to use coarsened exact matching on a panel dataset in order to obtain weights and use them in a fixed effect model. I think I have to do a reshape wide before going into cem procedure in order to have weights not varying over the id. My long-form dataset looks like the following:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(idfirm Year) float(inflow_ratio outflow_ratio agefirm) double tot_sales
     1 2008          .           .  0 211591.55354704778
     1 2009          0           0  1  308746.0587639413
     1 2010        .25           0  2  407237.1453954251
     1 2011         .4           0  3  598549.0481277383
     1 2012   .2857143           0  4  664061.6305459269
     1 2013   .5555556           0  5    608140.67505112
     1 2014   .3571429           0  6  715163.0758130773
     1 2015          0   .05263158  7  768412.7578732732
     2 2004          .           . 29  12237352.38962967
     2 2005          0           0 30 11513177.507807251
     2 2006          0           0 31 12304011.532418355
     2 2007          0           0 32 11406777.403632266
     2 2008  .16666667           0 33 12355367.684264863
     2 2009          0           0 34 12892224.398947667
     2 2010          0   .14285715 35 10897763.444727022
     2 2011          0           0 36  10580189.86100467
     2 2012          0           0 37 10967562.283051893
     2 2013          0           0 38  9124157.813647183
     2 2014          0    .3333333 39  7133930.997182059
     2 2015          0           0 40  5427924.711631365
     3 2004          .           .  9 2464566.2638161103
     3 2005  .23913044           0 10   4406664.46751826
     3 2006          0   .03508772 11  1843225.499704768
     3 2007          0   .14545454 12  476002.8259390887
     3 2008          0   .21276596 13  160865.5648153848
     3 2009          0    .1081081 14   82650.9899064962
     3 2010   .3030303           0 15 126687.58501765266
     3 2011          0     .372093 16  35362.49685707843
     3 2012          0    .4074074 17 16035.562916347304
     3 2013      .1875           0 18 22272.424034809985
     3 2014          0    .2105263 19  21090.64112449751
     3 2015          0   .26666668 20  23837.82400447101
     4 2004          .           .  4  8398246.263306491
     4 2005  .03947368           0  5  8251045.135936161
     4 2006   .0949367           0  6  9847010.316997783
     4 2007   .2485549           0  7 13503137.133153718
     4 2008   .1712963           0  8 13768126.595234673
     4 2009  .07509881           0  9  13834060.86932386
     4 2010 .025735294           0 10 12531817.194234656
     4 2011 .014336918           0 11 12433251.178176137
     4 2012  .03180212           0 12 11206517.411851741
     4 2013  .05821918           0 13 14594676.742348071
     4 2014  .05825243           0 14 26481277.906628065
     4 2015          0 .0091743115 15  29946995.67406721
     5 2007          .           .  0   39.4415442669969
     6 2004          .           . 29  28066686.19154623
     6 2005          0           0 30  5704381.338495776
     6 2006          0           0 31 496491.87314146105
     6 2007          0           0 32  9421.785319502253
     6 2008          0           0 33  394.3420099042942
     6 2009          0           0 34 1380.2071011962253
     7 2007          .           .  0  35459.78814655074
     7 2008          0           0  1  42076.49109553711
     7 2009          0           0  2   381988.536163157
     7 2010          0           0  3  451015.3511721381
     7 2011          0           0  4 270585.60116440145
     7 2012          0           0  5 329557.26253078564
     7 2013          0           0  6  305000.4474947418
     7 2014          0           0  7 173465.68589452517
     7 2015          0           0  8  31625.55690904084
     8 2004          .           . 43  1499855855.865098
     8 2005          0   .03007519 44 1689540069.7170644
     8 2006          0    .1627907 45  1598121054.119387
     8 2007          0    .0462963 46  1656992400.409758
     8 2008          0   .03883495 47   2142910992.52344
     8 2009          0    .1010101 48 2201020370.9059067
     8 2010          0    .0786517 49  2181284539.324025
     8 2011 .024390243           0 50 2029940306.3960855
     8 2012  .11904762           0 51 2225894374.1270456
     8 2013  .05319149           0 52  2727305730.021949
     8 2014          0           0 53 2359259573.3842134
     8 2015          0   .05050505 54  2370530389.480409
     9 2004          .           . 41   9917874207.75519
     9 2005          0           0 42 10607521709.816193
     9 2006          0   .03030303 43 11125455014.939121
     9 2007          0           0 44 10999908825.891459
     9 2008      .0625           0 45 11020835162.138296
     9 2009          0           0 46 11052308521.725805
     9 2010          0           0 47 11844314656.874342
     9 2011          0           0 48  12248782762.78322
     9 2012          0  .029411765 49 12198970579.756456
     9 2013          0    .0909091 50 11978041077.652853
     9 2014         .1           0 51 13100594403.908373
     9 2015  .03030303           0 52 16695333854.076557
    10 2004          .           .  1 20392.013641854945
    11 2008          .           .  0 1020956.3147491836
    11 2009          0           0  1  2431036.790986024
    11 2010          0           0  2  514778.3255435499
    11 2011          0           0  3  66955.82008718849
    11 2012          0          .5  4 1857.2792628005145
    11 2013          0           0  5  57300.58370722538
    11 2014          0           0  6  31166.09542619379
    12 2012          .           .  0 1399.3437130821144
    12 2013          0           0  1 46875.852646417305
    12 2014          0           0  2  92413.03425338621
    12 2015          0           0  3 120786.41920184325
    13 2004          .           .  2 3551802.0606248565
    13 2005          0           0  3  5632204.502071029
    13 2006          1           0  4 6445605.7851592805
    13 2007          0           0  5  5607216.736637451
    end
    What I did, is to reshape it wide and apply cem using the following code:

    Code:
    reshape wide inflow_ratio outflow_ratio nprod  agefirm tot_sales recalled_dummy_byfirm, i(idfirm) j(Year)
    *the following code is to create a unique treatment variable in the wide form:
    replace recalled_dummy_byfirm2004 = 1 if recalled_dummy_byfirm2005==1|recalled_dummy_byfirm2006==1|recalled_dummy_byfirm2007==1|recalled_dummy_byfirm2008==1|recalled_dummy_byfirm2009==1|recalled_dummy_byfirm2010==1|recalled_dummy_byfirm2011==1|recalled_dummy_byfirm2012==1|recalled_dummy_byfirm2013==1|recalled_dummy_byfirm2014==1|recalled_dummy_byfirm2015==1
    drop recalled_dummy_byfirm2005 recalled_dummy_byfirm2006 recalled_dummy_byfirm2007 recalled_dummy_byfirm2008 recalled_dummy_byfirm2009 recalled_dummy_byfirm2010 recalled_dummy_byfirm2011 recalled_dummy_byfirm2012 recalled_dummy_byfirm2013 recalled_dummy_byfirm2014 recalled_dummy_byfirm2015
    rename (recalled_dummy_byfirm2004) (trattamento)
    replace trattamento = 0 if trattamento==.
    cem  agefirm2004 agefirm2005 agefirm2006 agefirm2007 agefirm2008 agefirm2009 agefirm2010 agefirm2011 agefirm2012 agefirm2013 agefirm2014 agefirm2015 inflow_ratio2005 inflow_ratio2006 inflow_ratio2007 inflow_ratio2008 inflow_ratio2009 inflow_ratio2010 inflow_ratio2011 inflow_ratio2012 inflow_ratio2013 inflow_ratio2014 inflow_ratio2015 outflow_ratio2005 outflow_ratio2006 outflow_ratio2007 outflow_ratio2008 outflow_ratio2009 outflow_ratio2010 outflow_ratio2011 outflow_ratio2012 outflow_ratio2013 outflow_ratio2014 outflow_ratio2015, tr(trattamento)
    The result however is quite astonishing telling me that just one strata is matched and all 0 appears in te L1 statistic.
    What am I doing wrong?

    Thanks in advance,

    Federico
Working...
X