Announcement

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

  • Panel data Matching

    I am applying a propensity score matching. I have a Panay dataset with time dummy and time invariant treatment variable( dummy). I read that to match the observations, you should take the covariates and balance them. However, only pre-treatment observations of such covariates must be selected for the matching, unless the covariates are not affected by the treatment.

    My problem: If I filter the dataset only for the pre-treatment observations, I will get a final matched data with only the pre-treatment observations, which is not useful to me as I then need to run a regression with the full dataset of observations.

    Question: How can I filter the dataset to get pre-treatment observations only, get the matching, and then use the matched dataset with FULL observations (pre- and post-treatment) to run the final regression?

  • #2
    After you get the matched data for the pre-treatment observations, your data set will contain, in some way, information that indicates which controls are matched with each case. There may also be a variable that designates matched tuples, that is, a variable which takes on the same value for the case and all of its matched controls in a tuple, and takes on a different value for each matched tuple.

    What you need to do now is create from that a data set that contains the panel identifier as one variable and the tuple variable as the other. Then you merge that with the original complete panel data set so that the tuple number gets assigned to all of the observations (i.e. both pre- and post- treatment) for its member panels.

    If this description is too abstract and you need guidance writing code to do this, you need to post back with example data from your matched pre-treatment data and also example data from the original panel data. Use the -dataex- command to do that. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      something along the lines of

      egen finalwgt = mean(weight) , by(id)

      this will populate all periods with the mean of the weight (or whatever the matching algorithm provides you).

      Comment


      • #4
        Thank you, Clyde and George, for your responses. I truly appreciate it. I'm currently waiting for my professor to provide a Stata license, and I will share a sample as you suggested. Meanwhile, I'd like to understand how to perform matching when the dataset is in wide format. When data is transformed into wide format, variables are suffixed by year, creating a layout where each row represents an entity with multiple time-specific measurements. I've read that the data should be reshaped to wide format before performing pre-treatment matching and was wondering how that is done.

        Comment


        • #5
          You will need to transform the data to long layout in order to ultimately do your analyses. The matching could be done either before or after. The matching will be done on pre-treatment data only, so it's a matter of selecting the variables suffixed with pre-treatment years if you do it on the wide data, or selecting the observations where the year variable contains a pre-treatment value, when you do the matching.

          Converting the data from wide to long layout is done with the -reshape- command. The syntactic details of that command will depend on the details of the variable names and what variable(s) identify unique observations in the data set. And sometimes you have to prepare the data set first by renaming some variables or creating new variables. So while I could show you an example, the chance that it would materially differ from what you are working with is high. I think it would be best to postpone that until you are able to post example data.

          Comment


          • #6
            input str15 Country int Year byte(SR Year_2003) double(GDP ROL Regulatory Politicalstab Economicfree) float p_score double _pscore byte(_treated _support) double _weight int(_id _n1 _n2) float _nn double _pdif
            "Angola" 1996 0 0 6.54 -1.63 -1.42 -2.06 24 .20970742 .20970742404460907 0 1 . 18 . . 0 .
            "Angola" 1997 0 0 7.68 -1.58 -1.44 -2.19 24 .25129187 .2512918710708618 0 1 . 25 . . 0 .
            "Angola" 1998 0 0 6.51 -1.53 -1.45 -2.32 25 .3356498 .3356497585773468 0 1 .5 44 . . 0 .
            "Angola" 1999 0 0 6.15 -1.565 -1.48 -2.18 24 .26310876 .2631087601184845 0 1 . 27 . . 0 .
            "Angola" 2000 0 0 9.13 -1.6 -1.51 -2.04 24 .2103039 .2103039175271988 0 1 . 19 . . 0 .
            "Angola" 2001 0 0 8.94 -1.615 -1.4 -1.81 27.33333333333333 .21277876 .21277876198291779 0 1 . 21 . . 0 .
            "Angola" 2002 0 0 15.29 -1.63 -1.29 -1.58 30.66666666666666 .19162783 .19162783026695251 0 1 . 15 . . 0 .
            "Benin" 1996 1 0 2.36 .05 -.18 1.05 55 .3798474 .37984737753868103 1 1 1 104 46 . 1 .006311953067779541
            "Benin" 1997 1 0 2.27 .05 -.16 .9 61 .6196409 .6196408867835999 1 0 . 135 . . 0 .
            "Benin" 1998 1 0 2.46 .05 -.15 .74 62 .6980517 .6980516910552979 1 1 1 161 85 84 2 .00007587671279907227
            "Benin" 1999 1 0 3.68 -.06499999999999999 -.16 .77 61 .6240863 .6240862607955933 1 1 1 137 75 . 1 .00719904899597168
            "Benin" 2000 1 0 3.52 -.18 -.16 .8 62 .6124415 .6124415397644043 1 1 1 133 74 73 2 .0029338598251342773
            "Benin" 2001 1 0 3.67 -.22 -.36 .81 60 .5635818 .5635818243026733 1 1 1 123 65 64 2 .006257534027099609
            "Benin" 2002 1 0 4.19 -.26 -.57 .82 57 .4807903 .48079025745391846 1 1 1 116 56 57 2 .0009014308452606201
            "Botswana" 1996 1 0 4.85 .58 .65 1.02 62 .6297187 .6297186613082886 1 1 1 139 75 . 1 .0015666484832763672
            "Botswana" 1997 1 0 5.02 .605 .74 .99 59 .540101 .5401009917259216 1 1 1 121 60 59 2 .0025548934936523438
            "Botswana" 1998 1 0 4.79 .63 .83 .96 63 .6679452 .6679452061653137 1 1 1 153 79 80 2 .005587458610534668
            "Botswana" 1999 1 0 5.48 .605 .81 1.02 63 .6407625 .6407625079154968 1 1 1 148 76 77 2 .003968179225921631
            "Botswana" 2000 1 0 5.79 .58 .8 1.07 66 .7028413 .7028412818908691 1 1 1 162 85 . 1 .004865467548370361
            "Botswana" 2001 1 0 5.49 .5700000000000001 .85 .97 67 .7500182 .7500182390213013 1 1 1 173 90 . 1 .0012496113777160645
            "Botswana" 2002 1 0 5.44 .56 .9 .87 66 .7453523 .7453522682189941 1 1 1 171 90 . 1 .0034163594245910645
            "Cabo Verde" 1996 1 0 .5 1.04 -.53 1.04 50 .579946 .579945981502533 1 1 1 127 66 67 2 .0025715231895446777
            "Cabo Verde" 1997 1 0 .49 .855 -.49 1.08 48 .4407105 .44071051478385925 1 1 1 111 48 49 2 .004109323024749756
            "Cabo Verde" 1998 1 0 .52 .67 -.45 1.11 48 .3708623 .37086227536201477 1 1 1 103 46 . 1 .0026731491088867188
            "Cabo Verde" 1999 1 0 .59 .655 -.24 1.17 51 .406972 .4069719612598419 1 0 . 108 . . 0 .
            "Cabo Verde" 2000 1 0 .54 .64 -.02 1.22 52 .3845333 .3845333158969879 1 1 1 106 47 . 1 .006591141223907471
            "Cabo Verde" 2001 1 0 .56 .455 -.14 .98 56 .5600951 .5600950717926025 1 1 1 122 65 64 2 .0027707815170288086
            "Cabo Verde" 2002 1 0 .62 .27 -.26 .73 58 .6704111 .6704111099243164 1 1 1 154 80 81 2 .004589378833770752
            "Cameroon" 1996 1 0 11.09 -1.44 -1.12 -.96 46 .4629424 .4629423916339874 1 1 1 113 53 54 2 .0030153095722198486
            "Cameroon" 1997 1 0 10.79 -1.29 -1.02 -.87 45 .4301528 .4301528036594391 1 1 1 110 48 . 1 .00644838809967041
            "Cameroon" 1998 1 0 11.3 -1.14 -.91 -.78 48 .5189666 .5189666152000427 1 0 . 118 . . 0 .
            "Cameroon" 1999 1 0 11.57 -1.165 -.86 -.67 50 .52679396 .5267939567565918 1 1 1 119 59 . 1 .008992671966552734
            "Cameroon" 2000 1 0 10.57 -1.19 -.82 -.56 50 .4790291 .4790290594100952 1 1 1 115 56 57 2 .0008597671985626221
            "Cameroon" 2001 1 0 10.95 -1.23 -.92 -.62 53 .5968818 .5968818068504333 1 1 1 131 72 71 2 .006685853004455566
            "Cameroon" 2002 1 0 12.42 -1.27 -1.02 -.68 53 .6127951 .6127951145172119 1 1 1 134 74 73 2 .0032874345779418945
            "Chad" 1996 1 0 1.61 -1.26 -1.23 -1 45 .5683429 .568342924118042 1 0 . 125 . . 0 .
            "Chad" 1997 1 0 1.54 -1.225 -1.21 -1.16 45 .6314291 .631429135799408 1 1 1 141 75 . 1 .00014382600784301758
            "Chad" 1998 1 0 1.74 -1.19 -1.2 -1.31 47 .7396475 .7396475076675415 1 1 1 168 89 88 2 .004875004291534424
            "Chad" 1999 1 0 1.53 -1.16 -1.21 -1.22 47 .7232159 .7232159376144409 1 1 1 166 86 87 2 .007543385028839111
            "Chad" 2000 1 0 1.39 -1.13 -1.21 -1.13 47 .7045777 .7045777440071106 1 1 1 163 85 . 1 .006601929664611816
            "Chad" 2001 1 0 1.71 -1.12 -1.12 -1.34 46 .7301465 .7301464676856995 1 1 1 167 87 88 2 .0013431310653686523
            "Chad" 2002 1 0 2 -1.11 -1.03 -1.56 49 .838984 .838983952999115 1 0 . 195 . . 0 .
            "Congo-Brazza" 1996 0 0 2.54 -1.04 -1.23 -1.22 40 .5484653 .5484653115272522 0 1 . 62 . . 0 .
            "Congo-Brazza" 1997 0 0 2.32 -1.33 -1.27 -1.36 42 .5831032 .5831031799316406 0 1 1.5 67 . . 0 .
            "Congo-Brazza" 1998 0 0 1.95 -1.62 -1.3 -1.5 34 .3076569 .3076568841934204 0 1 .5 41 . . 0 .
            "Congo-Brazza" 1999 0 0 2.35 -1.485 -1.25 -1.21 42 .4798888 .47988882660865784 0 1 1 56 . . 0 .
            "Congo-Brazza" 2000 0 0 3.23 -1.35 -1.2 -.92 41 .3735354 .3735354244709015 0 1 3 46 . . 0 .
            "Congo-Brazza" 2001 0 0 2.8 -1.32 -1.1 -1.26 44 .58567625 .5856762528419495 0 1 . 70 . . 0 .
            "Congo-Brazza" 2002 0 0 3.03 -1.29 -1 -1.59 45 .7156726 .7156725525856018 0 1 1.5 86 . . 0 .
            "Djibouti" 1996 0 0 .49 -.97 -1 -.34 55 .6979758 .6979758143424988 0 1 5 85 . . 0 .
            "Djibouti" 1997 0 0 .5 -.94 -.95 -.65 55 .7845411 .7845410704612732 0 1 1 92 . . 0 .
            "Djibouti" 1998 0 0 .51 -.91 -.89 -.96 56 .8663924 .8663923740386963 0 1 1.5 98 . . 0 .
            "Djibouti" 1999 0 0 .54 -.895 -.8 -.6 57 .808341 .8083410263061523 0 1 3.5 95 . . 0 .
            "Djibouti" 2000 0 0 .55 -.88 -.71 -.24 55 .6511404 .6511403918266296 0 1 .5 78 . . 0 .
            "Djibouti" 2001 0 0 .57 -.9099999999999999 -.69 -.28 58 .7347725 .7347725033760071 0 1 1.5 89 . . 0 .
            "Djibouti" 2002 0 0 .59 -.94 -.67 -.31 58 .7337844 .7337844371795654 0 1 1.5 88 . . 0 .
            "Egypt" 1996 0 0 67.63 0 -.05 -.53 52 .4544291 .45442909002304077 0 1 .5 51 . . 0 .
            "Egypt" 1997 0 0 78.44 -.065 -.11 -.28 55 .3911245 .3911244571208954 0 1 2 47 . . 0 .
            "Egypt" 1998 0 0 84.83 -.13 -.17 -.02 56 .29418117 .2941811680793762 0 1 . 36 . . 0 .
            "Egypt" 1999 0 0 90.71 -.09 -.23 .02 58 .3266966 .32669660449028015 0 1 . 43 . . 0 .
            "Egypt" 2000 0 0 99.84 -.05 -.3 .05 52 .16094802 .1609480232000351 0 1 .5 7 . . 0 .
            "Egypt" 2001 0 0 96.68 -.03 -.38 -.18 52 .23594603 .23594602942466736 0 1 . 22 . . 0 .
            "Egypt" 2002 0 0 85.15 -.01 -.46 -.41 54 .4366012 .4366011917591095 0 1 2.5 48 . . 0 .
            "Eq Guinea" 1996 0 0 .23 -1.28 -1.44 -.13 45 .29911125 .2991112470626831 0 1 . 39 . . 0 .
            "Eq Guinea" 1997 0 0 .44 -1.315 -1.53 -.11 45 .29468027 .29468026757240295 0 1 . 37 . . 0 .
            "Eq Guinea" 1998 0 0 .37 -1.35 -1.63 -.08 45 .2898372 .28983721137046814 0 1 . 34 . . 0 .
            "Eq Guinea" 1999 0 0 .62 -1.345 -1.64 -.06 45 .28522518 .28522518277168274 0 1 . 33 . . 0 .
            "Eq Guinea" 2000 0 0 1.05 -1.34 -1.65 -.04 46 .3064595 .3064594566822052 0 1 .5 40 . . 0 .
            "Eq Guinea" 2001 0 0 1.46 -1.29 -1.57 -.28 48 .4477972 .4477972388267517 0 1 .5 49 . . 0 .
            "Eq Guinea" 2002 0 0 1.81 -1.24 -1.49 -.51 46 .4676541 .46765410900115967 0 1 1 54 . . 0 .
            "Ethiopia" 1996 1 0 8.55 -.97 -1.3 -1.05 46 .6706775 .6706774830818176 1 1 1 155 80 81 2 .004323005676269531
            "Ethiopia" 1997 1 0 8.59 -.94 -1.29 -.84 48 .6666448 .6666447520256042 1 1 1 151 79 80 2 .004287004470825195
            "Ethiopia" 1998 1 0 7.82 -.91 -1.27 -.63 49 .6360799 .6360799074172974 1 1 1 145 75 76 2 .004794597625732422
            "Ethiopia" 1999 1 0 7.7 -.9450000000000001 -1.29 -.79 47 .6238657 .6238657236099243 1 1 1 136 75 . 1 .007419586181640625
            "Ethiopia" 2000 1 0 8.24 -.98 -1.32 -.95 50 .747889 .74788898229599 1 1 1 172 90 . 1 .0008796453475952148
            "Ethiopia" 2001 1 0 8.23 -.97 -1.27 -1.09 49 .7583584 .7583584189414978 1 1 1 174 90 . 1 .009589791297912598
            "Ethiopia" 2002 1 0 7.85 -.96 -1.23 -1.23 50 .8132582 .813258171081543 1 1 1 191 96 95 2 .0024098753929138184
            "Gabon" 1996 0 0 5.69 -.65 .14 .13 56 .4659577 .4659577012062073 0 1 .5 53 . . 0 .
            "Gabon" 1997 0 0 5.33 -.51 .24 .23 59 .55471563 .554715633392334 0 1 1 64 . . 0 .
            "Gabon" 1998 0 0 4.48 -.37 .34 .33 59 .55015934 .5501593351364136 0 1 . 63 . . 0 .
            "Gabon" 1999 0 0 4.66 -.275 .21 .48 61 .6057644 .6057644486427307 0 1 1 73 . . 0 .
            "Gabon" 2000 0 0 5.08 -.18 .07 .64 58 .5003703 .5003703236579895 0 1 . 58 . . 0 .
            "Gabon" 2001 0 0 5.02 -.215 -.01 .52 55 .4495655 .44956547021865845 0 1 . 50 . . 0 .
            "Gabon" 2002 0 0 5.34 -.25 -.08 .41 58 .583129 .5831289887428284 0 1 .5 68 . . 0 .
            "Ghana" 1996 1 0 6.93 -.23 -.34 -.23 58 .8035387 .8035386800765991 1 1 1 185 94 95 2 .003807246685028076
            "Ghana" 1997 1 0 6.89 -.335 -.28 -.18 57 .7400599 .7400599122047424 1 1 1 169 89 88 2 .0052874088287353516
            "Ghana" 1998 1 0 7.48 -.44 -.22 -.14 57 .6927307 .6927306652069092 1 1 1 158 84 85 2 .00004684925079345703
            "Ghana" 1999 1 0 7.72 -.18 -.11 -.25 58 .7926198 .7926197648048401 1 1 1 182 93 94 2 .004246234893798828
            "Ghana" 2000 1 0 4.98 .08 0 -.36 58 .8589641 .8589641451835632 1 1 1 200 98 97 2 .007428228855133057
            "Ghana" 2001 1 0 5.31 .05 -.26 -.26 58 .8551653 .8551653027534485 1 1 1 199 97 . 1 .004965662956237793
            "Ghana" 2002 1 0 6.17 .02 -.51 -.16 57 .8317819 .8317819237709045 1 0 . 192 . . 0 .
            The above is the pre treatment matched dataset. SR is the treatment variable.


            Below is the original panal dataset
            input str15 Country int Year byte(SR Year_2003) double(GDP ROL Regulatory Politicalstab)
            "Angola" 1996 0 0 6.54 -1.63 -1.42 -2.06
            "Angola" 1997 0 0 7.68 -1.58 -1.44 -2.19
            "Angola" 1998 0 0 6.51 -1.53 -1.45 -2.32
            "Angola" 1999 0 0 6.15 -1.565 -1.48 -2.18
            "Angola" 2000 0 0 9.13 -1.6 -1.51 -2.04
            "Angola" 2001 0 0 8.94 -1.615 -1.4 -1.81
            "Angola" 2002 0 0 15.29 -1.63 -1.29 -1.58
            "Angola" 2003 0 1 17.81 -1.48 -1.19 -1.01
            "Angola" 2004 0 1 23.55 -1.52 -1.23 -1.06
            "Angola" 2005 0 1 36.97 -1.46 -1.24 -.89
            "Angola" 2006 0 1 52.38 -1.31 -1.16 -.54
            "Angola" 2007 0 1 65.27 -1.38 -1.08 -.67
            "Angola" 2008 0 1 88.54 -1.38 -1.1 -.36
            "Angola" 2009 0 1 70.31 -1.24 -1.06 -.35
            "Angola" 2010 0 1 83.8 -1.27 -1.06 -.23
            "Angola" 2011 0 1 111.79 -1.28 -1.11 -.37
            "Angola" 2012 0 1 128.05 -1.3 -.99 -.39
            "Angola" 2013 0 1 132.34 -1.29 -1.04 -.39
            "Angola" 2014 0 1 135.97 -1.07 -.86 -.33
            "Angola" 2015 0 1 90.5 -1.03 -.86 -.51
            "Angola" 2016 0 1 52.76 -1 -.97 -.32
            "Angola" 2017 0 1 73.69 -1.04 -1.05 -.39
            "Angola" 2018 0 1 79.45 -1 -.8 -.35
            "Angola" 2019 0 1 70.9 -1.03 -.83 -.37
            "Angola" 2020 0 1 48.5 -.95 -.86 -.6
            "Benin" 1996 1 0 2.36 .05 -.18 1.05
            "Benin" 1997 1 0 2.27 .05 -.16 .9
            "Benin" 1998 1 0 2.46 .05 -.15 .74
            "Benin" 1999 1 0 3.68 -.06499999999999999 -.16 .77
            "Benin" 2000 1 0 3.52 -.18 -.16 .8
            "Benin" 2001 1 0 3.67 -.22 -.36 .81
            "Benin" 2002 1 0 4.19 -.26 -.57 .82
            "Benin" 2003 1 1 5.35 -.43 -.62 .68
            "Benin" 2004 1 1 6.19 -.48 -.62 .27
            "Benin" 2005 1 1 6.57 -.53 -.64 .45
            "Benin" 2006 1 1 7.03 -.53 -.46 .55
            "Benin" 2007 1 1 8.17 -.51 -.51 .39
            "Benin" 2008 1 1 9.79 -.53 -.55 .38
            "Benin" 2009 1 1 9.74 -.65 -.4 .4
            "Benin" 2010 1 1 9.54 -.67 -.4 .26
            "Benin" 2011 1 1 10.69 -.66 -.4 .32
            "Benin" 2012 1 1 11.14 -.57 -.4 .36
            "Benin" 2013 1 1 12.52 -.57 -.42 .3
            "Benin" 2014 1 1 13.28 -.49 -.62 .03
            "Benin" 2015 1 1 11.39 -.55 -.62 -.02
            "Benin" 2016 1 1 11.82 -.63 -.58 -.01
            "Benin" 2017 1 1 12.7 -.64 -.52 .03
            "Benin" 2018 1 1 14.26 -.69 -.39 -.15
            "Benin" 2019 1 1 14.39 -.68 -.45 -.42
            "Benin" 2020 1 1 15.69 -.76 -.48 -.44
            "Botswana" 1996 1 0 4.85 .58 .65 1.02
            "Botswana" 1997 1 0 5.02 .605 .74 .99
            "Botswana" 1998 1 0 4.79 .63 .83 .96
            "Botswana" 1999 1 0 5.48 .605 .81 1.02
            "Botswana" 2000 1 0 5.79 .58 .8 1.07
            "Botswana" 2001 1 0 5.49 .5700000000000001 .85 .97
            "Botswana" 2002 1 0 5.44 .56 .9 .87
            "Botswana" 2003 1 1 7.51 .67 .84 1.1
            "Botswana" 2004 1 1 8.96 .56 .76 .92
            "Botswana" 2005 1 1 9.92 .54 .72 1.06
            "Botswana" 2006 1 1 9.92 .51 .61 1.02
            "Botswana" 2007 1 1 10.57 .54 .63 1.06
            "Botswana" 2008 1 1 10.73 .61 .64 1.03
            "Botswana" 2009 1 1 10.12 .59 .61 .95
            "Botswana" 2010 1 1 12.64 .6 .58 .99
            "Botswana" 2011 1 1 15.11 .6 .58 1.06
            "Botswana" 2012 1 1 13.91 .59 .69 1.1
            "Botswana" 2013 1 1 14.27 .49 .64 1.1
            "Botswana" 2014 1 1 15.47 .54 .76 1.01
            "Botswana" 2015 1 1 13.53 .48 .55 1.03
            "Botswana" 2016 1 1 15.08 .38 .73 .98
            "Botswana" 2017 1 1 16.11 .36 .59 1.01
            "Botswana" 2018 1 1 17.03 .38 .62 .96

            Thank you so much for your help again!

            Comment


            • #7
              input double ExportValue
              0
              0
              0
              0
              0
              0
              0
              .7843067424445805
              0
              0
              0
              0
              0
              .6175694593996821
              0
              0
              0
              0
              .8749339615194762
              0
              0
              0
              .2206284534507656
              0
              .9703988126078106
              .495826021792124
              0
              .9847328344547093
              0
              .4407583194998028
              .6666950879454533
              0
              .554997910349126
              .7856910232488903
              1.038348809233326
              .2681052149748673
              0
              0
              0
              .5410675672640728
              .8306139552230922
              .5522539364408291
              0
              0
              0
              0
              1.270285039574596
              1.935527732157835
              1.710580015847569
              1.764107532254123
              2.288677411325093
              2.289010700811265
              2.324873511239977
              2.321035605311489
              2.300001147268568
              2.19508174759073
              2.277961944853615
              2.289925748431764
              2.390233895004637
              2.425724240812337
              2.420889337330117
              2.429896679786986
              2.367255605245655
              2.343961248005496
              2.337504405297145
              2.365283851940717
              2.329243058244424
              2.269641407884545
              2.317957967822719
              2.304405975781764
              2.248083609957572
              2.066946321564632
              .9747784295582798
              .3809907161312385
              0
              1.478436743258952
              1.002303540956784
              1.067995854007512
              1.07650837712145
              2.05126844101486
              2.090870778148036
              2.129397268224106
              2.193842992236185
              2.198155499846087
              2.167316481473504
              this is the outcome variable, I forgot to include.

              Comment


              • #8
                Your matched data set appears to be output from the user-written -psmatch2- command. But it is not properly matched. Instead of matching countries to other countries, you have matched country-years to other country-years. And often, the same country is matched to different countries in different years. This is not suitable for your purposes.

                To match on pre-treatment covariates, you need to make a single observation per country that reflects its covariates over the years. One approach is to use the average of each covariate during the pre-treatment period and run -psmatch2- on that. That would go something like this:

                Code:
                use original_data_set, clear
                keep if Year < 2003 // KEEP ONLY PRE-TREATMENT DATA
                collapse (mean) GDP-Economicfree, by(Country)
                Some people prefer to match on values in the first year, or median values in the pre-treatment year, or some combinations of these statistics depending on the variables themselves.

                Another approach is to reshape the original data set to wide and match on all the pre-treatment covariates. This sometimes runs into problems, however, if the resulting number of covariates is too large for the number of countries. Anyway, the code for that would look like this:
                Code:
                use original_data_set, clear
                reshape wide GDP-Economicfree, i(country) j(year)
                Whichever of these things you do, you would then run -psmatch2- on the results of that. The resulting data set would be in long layout and you would not need to -reshape- it. If you plan to use propensity scores for weighting, then no additional work is needed. You need only -merge- that output back to the original data.

                Code:
                use results_of_psmatch2, clear
                merge 1:m Country using original_data
                You can then proceed with calculating the appropriate weight for your analysis (which is not the _weight variable that -psmatch gives you: it is 1/pscore for the treated group and 1/(1-pscore) for the untreated group).

                If you truly intend to do matched-pairs analysis using the propensity scores for matching, then there is more work that needs to be done--with the -psmatch2- output. If this is the case, please post back showing the fixed -psmatch2- output data set, again using -dataex-.

                Comment


                • #9
                  Thank you very much again for your help. I really appreciate it. Below is the psmatch2 dataset to do the matched pairs analysis
                  * Example generated by -dataex-. For more info, type help dataex
                  clear
                  input str15 Country double(GDP Economicfree Globalizationindex Politicalstab) float(SR p_score) double _pscore byte(_treated _support) double _weight byte(_id _n1) float _nn double _pdif
                  "Angola" 8.605714285714285 25.571428571428573 39.67142857142857 -2.025714285714286 0 .032411646 .03241164609789848 0 1 . 2 . 0 .
                  "Benin" 3.1642857142857146 59.714285714285715 39.80142857142857 .8414285714285715 1 .841762 .8417620062828064 1 1 1 27 13 1 .019646286964416504
                  "Botswana" 5.265714285714286 63.714285714285715 47.92857142857143 .9857142857142857 1 .737248 .7372480034828186 1 1 1 21 12 1 .08342260122299194
                  "Cabo Verde" .5457142857142857 51.857142857142854 43.15857142857144 1.0471428571428572 1 .3100629 .3100629150867462 1 1 1 15 7 1 .0014857351779937744
                  "Cameroon" 11.241428571428571 49.285714285714285 40.60857142857144 -.7342857142857142 1 .6315049 .6315048933029175 1 1 1 19 12 1 .02232050895690918
                  "Chad" 1.6457142857142857 46.57142857142857 31.247142857142855 -1.2457142857142858 1 .8880262 .8880261778831482 1 1 1 30 13 1 .026617884635925293
                  "Congo-Brazza" 2.602857142857143 41.142857142857146 43.80571428571428 -1.2942857142857143 0 .22579877 .22579877078533173 0 1 . 5 . 0 .
                  "Djibouti" .5357142857142857 56.285714285714285 38.15571428571428 -.48285714285714293 0 .9159746 .9159745573997498 0 1 4 14 . 0 .
                  "Egypt" 86.18285714285712 54.142857142857146 59.3657142857143 -.19285714285714284 0 .05914266 .05914265662431717 0 1 . 3 . 0 .
                  "Eq Guinea" .8542857142857143 45.714285714285715 37.632857142857134 -.17285714285714285 0 .4633312 .4633311927318573 0 1 . 10 . 0 .
                  "Ethiopia" 8.140000000000002 48.42857142857143 29.517142857142854 -.9400000000000001 1 .9200668 .920066773891449 1 1 1 32 14 1 .004092216491699219
                  "Gabon" 5.085714285714286 58 49.64142857142857 .39142857142857146 0 .50026083 .5002608299255371 0 1 . 11 . 0 .
                  "Ghana" 6.497142857142857 57.57142857142857 49.62714285714286 -.22571428571428573 1 .608703 .6087030172348022 1 1 1 18 12 1 .045122385025024414
                  "Kenya" 13.001428571428573 58.285714285714285 47.26714285714286 -.9614285714285715 1 .8307204 .8307203650474548 1 1 1 26 13 1 .030687928199768066
                  "Lesotho" .8985714285714286 48.285714285714285 43.118571428571435 .03285714285714286 1 .33401665 .3340166509151459 1 1 1 17 8 1 .0037780404090881348
                  "Libya" 30.667142857142856 32.714285714285715 41.44571428571429 -.5485714285714286 0 .025749745 .025749744847416878 0 1 . 1 . 0 .
                  "Madagascar" 4.755714285714285 53.714285714285715 34.82 .1 0 .8614083 .8614082932472229 0 1 8 13 . 0 .
                  "Malawi" 3.2085714285714286 55.285714285714285 36.94714285714286 -.21 1 .8913372 .8913371562957764 1 1 1 31 14 1 .02463740110397339
                  "Mauritius" 4.461428571428571 68.14285714285714 53.59714285714285 .9657142857142855 1 .746123 .7461229562759399 1 1 1 22 12 1 .09229755401611328
                  "Morocco" 44.144285714285715 62.857142857142854 52.25142857142857 -.03142857142857143 0 .6538254 .6538254022598267 0 1 5 12 . 0 .
                  "Mozambique" 5.467142857142858 50.42857142857143 36.934285714285714 .024285714285714282 1 .6897736 .6897735595703125 1 1 1 20 12 1 .03594815731048584
                  "Namibia" 3.8157142857142863 64.71428571428571 49.80285714285714 .2885714285714286 1 .8274251 .8274250626564026 1 1 1 25 13 1 .03398323059082031
                  "Nigeria" 128.84714285714284 51.714285714285715 46.87714285714286 -1.16 1 .323321 .32332098484039307 1 1 1 16 8 1 .014473706483840942
                  "Rwanda" 1.912857142857143 41.714285714285715 28.622857142857146 -1.8157142857142858 1 .8744305 .8744305372238159 1 1 1 28 13 1 .013022243976593018
                  "Sao Tome & Prin" 3.6842857142857146 44 33.135714285714286 .9814285714285715 0 .3069181 .30691808462142944 0 1 . 6 . 0 .
                  "Senegal" 6.461428571428571 59.142857142857146 48.021428571428565 -.637142857142857 1 .80664 .8066400289535522 1 1 1 23 13 1 .054768264293670654
                  "Seychelles" .6428571428571429 48 48.91428571428571 1.0914285714285714 0 .06457134 .06457134336233139 0 1 . 4 . 0 .
                  "Sierra Leone" .8685714285714285 46 28.349999999999998 -1.6671428571428568 1 .9435723 .9435723423957825 1 1 1 33 14 1 .027597784996032715
                  "South Africa" 150.42571428571426 63.57142857142857 56.14 -.35857142857142854 0 .3551464 .3551464080810547 0 1 . 9 . 0 .
                  "Tanzania" 11.462857142857143 58 42.10142857142857 -.5057142857142857 1 .8823584 .8823584318161011 1 1 1 29 13 1 .020950138568878174
                  "Tunisia" 21.68 62.142857142857146 58.815714285714286 .25285714285714284 0 .3377947 .337794691324234 0 1 2 8 . 0 .
                  "Uganda" 6.1571428571428575 63.142857142857146 38.77428571428572 -1.302857142857143 1 .9887822 .9887821674346924 1 1 1 34 14 1 .07280761003494263
                  "Zambia" 3.8171428571428576 61.714285714285715 48.044285714285714 -.017142857142857144 1 .8132151 .8132151365280151 1 1 1 24 13 1 .048193156719207764
                  "Zimbabwe" 7.164285714285713 44.57142857142857 44.06285714285714 -1.0142857142857142 0 .3085772 .30857717990875244 0 1 1 7 . 0 .
                  end

                  Comment


                  • #10
                    The following will assign pair numbers to the matches and then import them to the original data file:
                    Code:
                    use matching_results, clear
                    keep Country _id _n1
                    sort _id
                    gen Country0 = Country[_n1]
                    keep Country Country0
                    rename Country Country1
                    
                    gen `c(obs_t)' pair_num = _n
                    
                    reshape long Country, i(pair_num)
                    drop _j
                    drop if missing(Country)
                    tempfile crosswalk
                    save `crosswalk'
                    
                    use original_full_data_set, clear
                    
                    joinby Country using `crosswalk', unmatched(master)
                    The end result of this will look like the original data set but with an additional variable showing which pairing(s) each country participates in. Note that the same country, if it is untreated, may be paired with more than one treated country--this is not a problem. This data set is in long layout, just as the original is, and is ready for matched pair analysis.

                    As an aside, if you read the literature on the use of propensity scores you will find that there are many opinions about the best way to do so. I don't want to go into a long discussion about this controversy. But I do want to leave you with my opinion that inverse probability weighting (see #8) is better than matching. It is simpler to implement, and it does not add a third level to the analytic model.

                    So, if this were my project, I probably would not go down this matching route. But if you wish to do that, I have shown you a path to get there.

                    Comment


                    • #11
                      Thank you so much again. I was lost before coming to Statlist, and I really appreciate your help in guiding me. Sorry for the back and forth questions, but one last question before I wrap up this discussion. I implemented IPW as suggested, so just for clarification, here’s what I’ve done:

                      For ATE:

                      * Calculate inverse probability weights for both groups
                      gen weight = 1 / p_score if SR == 1
                      replace weight = 1 / (1 - p_score) if SR == 0

                      * Applying weights for regression analysis to estimate ATE
                      reg ExportValue SR [aweight= weight] if _support, robust

                      For ATT:

                      * Calculate weights for the control group for ATT estimation
                      gen weight = 1 / (1 - p_score) if SR == 0
                      replace weight = 1 if SR == 1 // Treat group weights set to 1 as they represent themselves

                      * Apply weights for regression analysis to estimate ATT
                      reg ExportValue SR [aweight= weight] if _support, robust

                      is this correct?

                      Please correct me if I am wrong, as I am learning and finding my way through these concepts. Again, I really, really appreciate your help

                      Comment


                      • #12
                        Yes, this is correct.

                        Comment


                        • #13
                          Thank you very much!!

                          Comment


                          • #14
                            Do we check the balance of the covariates in the pre-treatment matched sample? or after merging with the original dataset and applying the inverse probability weights (IPTW)? It’s a bit confusing. My understanding is that I applied IPTW after the data merge, so to assess the effectiveness of the IPTW, shouldn't I check the balance after the merge, particularly in the pre-treatment period? I couldn't find a clear source online for this scenario, so I would greatly appreciate your insights

                            Comment


                            • #15
                              You can examine the balance on the pre-treatment observations using the -mean- command for continuous variables and the -proportion- command for discrete variables, or, if you prefer, using the -table- command. Whichever of those you choose, you must use the propensity weights as -pweight-s for this.

                              Comment

                              Working...
                              X