Announcement

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

  • Synthetic control - synth2: invalid syntax error

    Hi everyone,

    I am struggling with a SSC command called -synth2-. Basically, when I run this, I got an error:


    Code:
    xtset idprovdis moyr_matricula
    
    
    foreach a in HEV{
    preserve
    ge `a'=(d_dum_`a'/tot)    
    synth2 `a'  car_pct pp_euro hh_t frac_age_15to59 frac_age_under15 avgHHmem frac_Male ///
        , trunit(29) trperiod(`=tm(2018m5)') xperiod(`=tm(2016m1)'(1)`=tm(2019m12)') nested frame(`a')    
    matrix R = e(U_wt)
    mat2txt, matrix(R) saving("${resultd}/T2_`a'W.txt") replace format(%6.1f)
    
    matrix R = e(bal)
    matselrc R R1, row(1,2,3,4,5,6,7) col(1,2,3)
    mat list R1 , format(%12.2f)
    matmap R1 R, map(round(@, 0.001))
    local att : di %6.3f  scalar(`e(att)')
    di "`att'"
    
    esttab matrix(R) using "$resultd/T2_baltab_`a'.tex",  ///
        nomtitle replace nonote label booktabs star(* 0.10 ** 0.05 *** 0.01) ///
        stats("`att'", labels("Avg effects: `att'") fmt(0 3 0 0))
    restore
    }
    Here is a dataex:



    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int moyr_matricula float(idprovdis d_dum_HEV d_dum_ZERO) long tot float(car_pct age_t0014 age_t1529) double(male pp_euro hh_t p_t) int dum_HEV
    672 1  31  -1  3555  .3368989 1589.2397  1622.082 5234.175438596491 11651.068591234956 4315.0935672514615  10552.12865497076  66
    673 1  22   0  5790  .5470662 1597.5385 1630.1775 5249.881656804734  11589.04063402938  4321.449704142012 10583.727810650887  43
    674 1  58 -16 11719 1.0836304  1629.006 1662.9337 5363.493975903614 11692.594201406531  4422.879518072289 10814.572289156626  79
    675 1  27   1  4716  .4371363 1626.6205 1658.9097 5350.704819277108  11660.94775176064  4411.704819277108 10788.397590361446  51
    676 1 141  -2  8291  .7751926 1614.6946 1647.2395 5304.790419161676 11512.580575615591  4366.904191616766 10695.407185628743 161
    677 1  90   1  8198  .7737827    1596.4 1628.5177 5255.535294117647 11636.280418159304  4331.729411764706  10594.70588235294 116
    678 1  35  -1  4408  .4249181  1563.155  1594.207 5145.781609195402 11651.257659136743  4241.350574712644 10373.764367816091  75
    679 1  24  -1  2509 .22847965 1659.6173 1692.9198 5446.246913580247 11617.824744020807  4481.333333333333 10981.283950617284  59
    680 1  33  -2  3064 .28978604 1593.8823    1626.7  5244.64705882353  11598.39329241222 4320.6882352941175 10573.317647058824  81
    681 1  58  -2  3310  .3255998 1531.8757  1564.548 5042.864406779661  11558.32863221045  4153.299435028249 10165.853107344632  70
    end
    format %tm moyr_matricula
    label values idprovdis idprovdis
    label def idprovdis 1 "A", modify


    The error I got every time:

    Code:
    invalid syntax
    r(198);

    Could anyone help me with that, please?

    Thanks a lot!
    Last edited by Michael Duarte Goncalves; 01 Oct 2024, 10:11.

  • #2
    I can assist on the condition that you say what you want to do with this code.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int moyr_matricula float(idprovdis d_dum_HEV d_dum_ZERO) long tot float(car_pct age_t0014 age_t1529) double(male pp_euro hh_t p_t) int dum_HEV
    672 1  31  -1  3555  .3368989 1589.2397  1622.082 5234.175438596491 11651.068591234956 4315.0935672514615  10552.12865497076  66
    673 1  22   0  5790  .5470662 1597.5385 1630.1775 5249.881656804734  11589.04063402938  4321.449704142012 10583.727810650887  43
    674 1  58 -16 11719 1.0836304  1629.006 1662.9337 5363.493975903614 11692.594201406531  4422.879518072289 10814.572289156626  79
    675 1  27   1  4716  .4371363 1626.6205 1658.9097 5350.704819277108  11660.94775176064  4411.704819277108 10788.397590361446  51
    676 1 141  -2  8291  .7751926 1614.6946 1647.2395 5304.790419161676 11512.580575615591  4366.904191616766 10695.407185628743 161
    677 1  90   1  8198  .7737827    1596.4 1628.5177 5255.535294117647 11636.280418159304  4331.729411764706  10594.70588235294 116
    678 1  35  -1  4408  .4249181  1563.155  1594.207 5145.781609195402 11651.257659136743  4241.350574712644 10373.764367816091  75
    679 1  24  -1  2509 .22847965 1659.6173 1692.9198 5446.246913580247 11617.824744020807  4481.333333333333 10981.283950617284  59
    680 1  33  -2  3064 .28978604 1593.8823    1626.7  5244.64705882353  11598.39329241222 4320.6882352941175 10573.317647058824  81
    681 1  58  -2  3310  .3255998 1531.8757  1564.548 5042.864406779661  11558.32863221045  4153.299435028249 10165.853107344632  70
    end
    format %tm moyr_matricula
    label values idprovdis idprovdis
    label def idprovdis 1 "A", modify
    
    cls
    
    xtset idprovdis moyr_matricula
    
    
    foreach a in HEV{
    preserve
    ge `a'=(d_dum_`a'/tot)    
    synth2 `a'  car_pct pp_euro hh_t frac_age_15to59 frac_age_under15 avgHHmem frac_Male ///
        , trunit(29) trperiod(`=tm(2018m5)') xperiod(`=tm(2016m1)'(1)`=tm(2019m12)') nested frame(`a')    
    matrix R = e(U_wt)
    mat2txt, matrix(R) saving("${resultd}/T2_`a'W.txt") replace format(%6.1f)
    
    matrix R = e(bal)
    matselrc R R1, row(1,2,3,4,5,6,7) col(1,2,3)
    mat list R1 , format(%12.2f)
    matmap R1 R, map(round(@, 0.001))
    local att : di %6.3f  scalar(`e(att)')
    di "`att'"
    
    esttab matrix(R) using "$resultd/T2_baltab_`a'.tex",  ///
        nomtitle replace nonote label booktabs star(* 0.10 ** 0.05 *** 0.01) ///
        stats("`att'", labels("Avg effects: `att'") fmt(0 3 0 0))
    restore
    }
    This so far returns me

    Code:
    invalid trunit() -- treatment unit not found in panelvar
    r(198);
    What is this
    Code:
    ge `a'=(d_dum_`a'/tot)
    meant to do? Are you trying to loop through these variables: d_dum_HEV d_dum_ZERO?

    Comment


    • #3
      Thanks for your help!

      Ok sorry, I should have put the correct -trunit()-. This code was shared to me, I am sorry if it is not clear.
      Here is a new dataex with the treated unit that I want:


      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float idprovdis int moyr_matricula long tot int dum_ECO long dum_NONECO int(dum_ZERO dum_HEV) double(p_t hh_t pp_euro male female) float(age_t1529 age_t0014 year d_dum_HEV d_dum_ZERO car_pct)
      29 672 24397 108 24289  22 657 25458.602409638555 10187.787148594378  16440.84132968004 12184.361445783132 13274.240963855422 3897.8474 3956.4216 2016 501   13  .9583008
      29 673 39022  83 38939  17 799          25314.668          10131.064  16340.72297907602          12114.596          13200.072  3875.144   3932.62 2016 679    7 1.5414778
      29 674 37804 203 37601  98 762  25163.76984126984 10070.559523809523 16359.013375946382 12043.567460317461 13120.202380952382      3852  3912.032 2016 579   54 1.5023186
      29 675 34123 247 33876 104 677 25851.738775510203 10344.873469387756 16476.383002090155 12371.567346938775 13480.171428571428 3957.8286  4017.743 2016 522   86   1.31995
      29 676 41157 237 40920 100 844 24869.894117647058  9951.078431372549 16379.032240419223            11903.2  12966.69411764706  3808.043   3865.69 2016 667   80 1.6548924
      29 677 46774 138 46636  35 807 24405.919230769232             9766.2 16293.284370837962 11681.392307692307 12724.526923076923  3736.923  3792.869 2016 624   -3 1.9165022
      29 678 30770 148 30622  73 850 24436.384615384617  9777.165384615384 16323.803705823457 11697.026923076923 12739.357692307693  3741.277 3800.1384 2016 567   51  1.259188
      29 679 14903  96 14807  42 590          24749.625      9906.57421875 16308.201542087623       11845.421875       12904.203125  3787.195 3846.6836 2016 386   19  .6021506
      29 680 19824 121 19703  43 747  24966.55905511811  9990.535433070867 16399.314690861123 11949.086614173228 13017.472440944883  3822.992  3879.823 2016 458   22  .7940221
      29 681 20739  86 20653  40 758 25495.787148594376 10200.546184738956 16480.812860218346 12202.678714859438  13293.10843373494  3903.233  3966.731 2016 572 -172  .8134285
      end
      format %tm moyr_matricula
      label values idprovdis idprovdis
      label def idprovdis 29 "M", modify
      What is this

      Code:
      ge `a'=(d_dum_`a'/tot) meant to do? Are you trying to loop through these variables: d_dum_HEV d_dum_ZERO?
      I think the person wanted to create a new variable called "HEV" and "ZERO" for further plotting. So yes, I rather say than yes, I want to loop through those variables:

      Code:
      preserve
      foreach a in ZERO{
      frame change `a'
      preserve
      drop if mi(pred·`a')
      
      twoway (tsline `a', lcolor(black) lwidth(medthick) lpattern(solid)) ///
      (tsline pred·`a', lcolor(green) lwidth(medium) lpattern(shortdash)), ///
          ytitle(Shares of EVs,size(huge)) ///
          ttitle(Year - Month,size(huge)) xlabel(`=tm(2016m1)' `=tm(2018m5)'  `=tm(2019m9)',labsize(huge)) ylabel(0(0.05)0.1,labsize(huge)) ///
          legend(order(1 "Madrid" 2 "Synthetic Madrid") size(huge) ///
          region(fcolor(none)) ///0
          position(11)  ///
          ring(0)) tli(`=tm(2018m5)', lpat(dash) lcol(black)) name(obspred, replace)
      graph export "$plotd\FIG2_synthM`a'.png", name(obspred) replace    
      
      ge diff=`a'-pred·`a'
      twoway (tsline diff, lcolor(black) lwidth(medthick) lpattern(solid)), ///
          ytitle(Gaps in shares of EVs,size(huge)) ///
          ttitle(Year - Month,size(huge)) xlabel(`=tm(2016m1)' `=tm(2018m5)'  `=tm(2019m9)',labsize(huge)) ylabel(0(0.05)0.1,labsize(huge)) ///
          tli(`=tm(2018m5)', lpat(dash) lcol(black)) name(te, replace)
      graph export "$plotd\FIG2_synthM`a'_TE.png", name(te) replace 
      restore
       frame change default
      } 
      restore

      Finally, here is the final aim of all that:

      Code:
      foreach a in HEV{
      preserve
      frame change `a'
      drop if mi(pred·`a')
      
      twoway (tsline `a', lcolor(black) lwidth(medthick) lpattern(solid)) ///
      (tsline pred·`a', lcolor(green) lwidth(medium) lpattern(shortdash)), ///
          ytitle(Shares of Hybrids,size(huge)) ///
          ttitle(Year - Month,size(huge)) xlabel(`=tm(2016m1)' `=tm(2018m5)' `=tm(2019m11)',labsize(huge)) ylabel(0(0.05)0.15,labsize(huge)) ///
          legend(order(1 "Madrid" 2 "Synthetic Madrid") size(huge) ///
          region(fcolor(none)) ///
          position(11)  ///
          ring(0)) tli(`=tm(2018m5)', lpat(dash) lcol(black)) name(obspred, replace)
      graph export "$plotd\FIG2_synthM`a'.png", name(obspred) replace    
      
      ge diff=`a'-pred·`a'
      twoway (tsline diff, lcolor(black) lwidth(medthick) lpattern(solid)), ///
          ytitle(Gaps in shares of Hybrids,size(huge)) ///
          ttitle(Year - Month,size(huge)) xlabel(`=tm(2016m1)' `=tm(2018m5)' `=tm(2019m11)',labsize(huge)) ylabel(0(0.05)0.1,labsize(huge)) ///
          tli(`=tm(2018m5)', lpat(dash) lcol(black)) name(te, replace)
      graph export "$plotd\FIG2_synthM`a'_TE.png", name(te) replace 
      restore
       frame change default
      }
      And this person does a placebo test as well by similar means:

      Code:
      foreach a in HEV ZERO {
      preserve
      ge `a'=(d_dum_`a'/tot)    
      synth2 `a' car_pct pp_euro hh_t frac_age_15to59 frac_age_under15 avgHHmem frac_Male ///
          , trunit(29) trperiod(`=tm(2018m5)') xperiod(`=tm(2016m1)'(1)`=tm(2019m12)') nested frame(`a'pcbunit)     ///
           placebo(unit cut(5)) sigf(6)
      *graph export "$plotd\FIG2C_synthM`a'pcbunit.png", name(eff_pboUnit) replace 
      restore    
      }
      
      foreach a in HEV {
      frame change `a'pcbunit
      preserve
      ge diff=`a'-pred·`a'
      *Pre MSPE of Fake Unit/ Pre MSPE of Treated Unit
      ge diff2=diff^2
      bys idprovdis: egen premspe = mean(diff2) if moyr_p<`=tm(2018m5)'
      ge premspeT=premspe if idprovdis==29
      egen t = max(premspeT)
      replace premspeT=t if mi(premspeT)
      drop t
      ge r=premspe/premspeT if  moyr_p<`=tm(2018m5)'
      bys idprovdis: egen t = max(r)
      replace r=t if mi(r)
      drop t
      
      
      drop if r>5
      egen gmean = mean(diff), by(moyr_p idprovdis)
      replace gmean=. if idprovdis!=29
      linkplot diff moyr_p, link(idprovdis) recast(line) lc(gs13) ///
          plot(line gmean moyr_p, lw(medthick))  xlabel(`=tm(2016m1)' `=tm(2018m5)' `=tm(2019m9)') ///
          ylabel(0(0.05)0.1,labsize(huge)) xlabel(,labsize(huge)) ///
          legend(order(2 "Madrid" 1 "Control Provinces") size(huge) ring(0) pos(11)) ///
          ytitle(Gaps in shares of Hybrids, size(huge)) ttitle(Year - Month, size(huge))
      graph export "$plotd\FIG2C_synthM`a'pcbunit.png", replace 
      restore
      }
      Thanks again for your help!

      Comment


      • #4
        Wait, now something more important is unclear. Are you saying that you did not write the code yourself? Who is "this person" you speak of?

        This is a better step, but now I need a fuller dataset. Give me the treated unit and say 4 to 5 controls. Then, produce the error you're getting with the data example. I guess that's my point, the error you're getting needs to be reproducible with the example data, and at present we can't do this

        Comment


        • #5
          Oh, I see. Thank you for your answer! Sorry for the small sample and irrelevant.

          Here is the new dataex, with some controls and time periods of interest for the synthetic control:

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float idprovdis int moyr_matricula long tot int dum_ECO long dum_NONECO int(dum_ZERO dum_HEV) double(p_t hh_t pp_euro male female) float(age_t1529 age_t0014 age_t60pl year)
           5 698 12803  445 12358  104  754 16319.816023738873  6559.581602373887 15916.311883765242  7962.323442136499  8357.492581602373 2442.7715  2534.994 3898.9614 2018
           6 698   914    1   913    0   52  4689.248120300752 1825.0225563909773   9425.93074628905 2318.4887218045114 2370.7593984962405   818.218   702.015 1094.0828 2018
          19 698  1285   10  1275    1   87           6002.875  2388.215277777778 10048.051183823418 2950.9930555555557 3051.8819444444443 1034.6459  938.3055  1330.375 2018
          27 698   501    2   499    0   47  4670.190476190476 1935.1746031746031 12958.008543402206 2288.6825396825398 2381.5079365079364  677.7302  707.4603 1174.3016 2018
          29 698 49485  797 48688  183 2125 24370.555555555555  9750.570881226053 16354.604326224315 11666.019157088123 12704.536398467433 3731.1035  3790.444  5479.647 2018
          48 698   790   11   779    6   49  5554.136363636364 2338.1363636363635 12690.952611703658 2692.6704545454545  2861.465909090909       732  771.4432  1513.625 2018
           5 699 12110  519 11591  114  822  16541.63253012048  6648.731927710844 15966.265943465127  8070.168674698795  8471.463855421687   2475.91 2570.3855  3951.253 2018
           6 699   833   13   820    1   39               5019 1950.3801652892562   9519.27097521117 2480.2396694214876 2538.7603305785124  876.3471  755.2479 1164.2067 2018
          19 699  1318   13  1305    1   79            5820.28 2316.0666666666666  9978.469179244856            2862.04            2958.24 1002.9467  907.8267 1293.5734 2018
          27 699   459    4   455    1   33 5035.6551724137935  2082.689655172414 12937.483368257732 2463.0344827586205 2572.6206896551726  732.3793  768.8104 1254.1724 2018
          29 699 45255 1139 44116  174 2539 24998.267716535433 10001.448818897637 16448.441433000087  11965.13779527559 13033.129921259842  3828.205  3886.417  5622.453 2018
          48 699   733   15   718    5   50               5988 2516.5185185185187 12811.549995022013 2900.1234567901233 3087.8765432098767  792.9506  831.5926 1631.7037 2018
           5 700 15069  617 14452   72  929  16665.60606060606  6697.721212121212 15977.868685685284  8130.878787878788  8534.727272727272  2494.203  2589.506  3981.373 2018
           6 700   865    8   857    2   45 4882.1984126984125 1897.8174603174602  9507.031419551395 2412.9761904761904  2469.222222222222  854.1349  733.2222  1133.254 2018
          19 700  1351   14  1337    0   88  5863.163265306122  2332.598639455782 10048.499691949206 2881.9727891156463  2981.190476190476 1009.3062  916.9184  1297.374 2018
          27 700   525    6   519    0   38  4918.033333333334             2036.5 12990.762508797317 2409.2833333333333            2508.75     715.1     747.9 1230.2667 2018
          29 700 50289 1171 49118  132 3092  24534.14671814672  9816.181467181466  16426.38897442293 11743.710424710425 12790.436293436293  3756.297  3815.811  5515.645 2018
          48 700   797   18   779    0   76  6040.925925925926 2540.4444444444443 12944.507206990487 2929.1975308641977 3111.7283950617284  796.5803  839.5185  1645.074 2018
           5 701 14020  556 13464   65  994  16217.10029498525 6517.0353982300885 15827.133560538923 7912.2684365781715   8304.83185840708 2426.8467  2519.283  3874.879 2018
           6 701   928    9   919    1   30           4589.875 1785.9338235294117  9353.565051884838 2269.8970588235293 2319.9779411764707   800.728  688.6912 1070.7206 2018
          19 701  1355   21  1334    2   82  5832.216216216216  2317.391891891892 10009.632110877736 2866.9054054054054  2965.310810810811   1005.75  912.3649 1289.1554 2018
          27 701   529    3   526    0   33  5734.137254901961  2371.549019607843  13180.79175464488  2805.627450980392 2928.5098039215686  835.2549  875.0588 1428.5686 2018
          29 701 55469 1560 53909  182 4654 24634.422480620156  9854.813953488372 16432.322979194225 11791.267441860466  12843.15503875969  3772.205   3831.88  5538.771 2018
          48 701   807   19   788    1   44   5419.32967032967   2280.78021978022 12869.239684048645 2629.8241758241757 2789.5054945054944  713.1868  751.7582  1479.099 2018
           5 702 15604  690 14914   82  898  16200.95588235294  6510.294117647059  15909.10105511216  7904.976470588235  8295.979411764705   2425.65  2517.029  3870.294 2018
           6 702  1123    5  1118    0   58 4433.2535211267605 1724.7535211267605  9290.833565366207 2192.6619718309857 2240.5915492957747  774.5493  663.7253      1034 2018
          19 702  1487   24  1463    3   77  5830.790540540541  2319.635135135135 10009.812361854458 2866.9864864864867  2963.804054054054 1002.9054  911.3041 1293.5067 2018
          27 702   598    3   595    0   35  5227.160714285715 2159.9464285714284 13044.991219042244  2558.785714285714           2668.375  760.3214  795.1964 1306.5358 2018
          29 702 41710 1666 40044  217 3755 24900.972549019607  9963.184313725491 16399.558431590605 11918.392156862745 12982.580392156862  3812.408  3873.106  5598.945 2018
          48 702   955   15   940    4   51  5356.652173913043            2255.75 12640.791874081595 2597.8152173913045  2758.836956521739  705.8152  740.3587 1464.9022 2018
           5 703 10605  345 10260   34  746 16542.683734939757  6648.656626506024 15873.592083394527   8070.69578313253  8471.987951807228  2476.274  2569.946  3951.976 2018
           6 703   927    7   920    0   34  4594.462686567164  1784.858208955224  9378.004817972573 2271.5522388059703  2322.910447761194  803.4478  691.1716 1064.6791 2018
          19 703  1457   13  1444    0  100 5739.3708609271525 2285.3708609271525  9995.038375735761 2822.3576158940396 2917.0132450331125  988.4172  895.0662 1275.9602 2018
          27 703   504    3   501    0   35  4461.805970149254 1849.6119402985075 12877.919045242645 2188.9402985074626  2272.865671641791  647.4627  674.0448 1124.4329 2018
          29 703 32305 1730 30575  137 2222  25268.65338645418  10111.25498007968 16421.419702786403 12093.290836653387 13175.362549800797 3868.1475  3929.705  5682.104 2018
          48 703   883   13   870    2   64  6118.848101265823  2575.025316455696 12911.504388791162 2963.4177215189875 3155.4303797468356  806.8354  849.7342 1667.6582 2018
           5 704  7922  343  7579   81  702 16938.956790123455  6807.049382716049  15950.26693640691  8263.225308641975  8675.731481481482   2536.12  2630.904  4048.028 2018
           6 704   691    6   685    1   49           4830.384           1876.768    9434.6067346788           2387.184             2443.2    844.48    728.48  1117.712 2018
          19 704   906    9   897    5   62  6443.099236641221 2559.5648854961833 10166.699778344315 3162.7786259541986  3280.320610687023 1111.3359 1011.7405 1417.4275 2018
          27 704   344    4   340    0   27  5759.448979591837 2382.6326530612246 13259.241905579127 2813.6938775510203 2945.7551020408164  839.8163  879.8979  1429.306 2018
          29 704 18678  848 17830  248 2009 25575.798387096773  10232.95564516129 16476.577708557765 12240.108870967742 13335.689516129032  3915.617  3977.863  5751.653 2018
          48 704   562   11   551    1   50  6513.438356164384 2744.8630136986303 13166.199548379322 3151.5342465753424  3361.904109589041   855.863  909.6849 1769.5616 2018
           5 705 10589  593  9996  120  862 16325.353115727003  6560.964391691395  15914.70090610372  7964.961424332344   8360.39169139466 2444.3176  2535.638  3901.024 2018
           6 705   856   20   836    9   53  4664.087591240876  1816.043795620438  9422.150748349253  2307.058394160584  2357.029197080292   813.781  696.3431 1094.1825 2018
          19 705  1274   19  1255    0  118  5739.907284768212 2281.5099337748343  9947.858435898377 2822.0529801324506 2917.8543046357618  989.1259  896.8079  1271.437 2018
          27 705   456    6   450    0   45  4784.870967741936 1982.4516129032259 12979.695016186879  2344.951612903226 2439.9193548387098  694.9194  724.3065 1201.9839 2018
          29 705 24092 1371 22721  260 2714 24443.203846153847  9779.996153846154 16382.506235438746 11700.384615384615 12742.819230769232 3742.0884  3801.077      5497 2018
          48 705   658   29   629    8   46          6107.4375           2568.225 12930.896531367545             2959.9          3147.5375   806.275   849.175 1663.8125 2018
           5 706 11713  356 11357   84  851  16568.91265060241  6657.993975903614 15945.860189138648  8083.512048192771  8485.400602409638  2480.434  2573.994 3959.3855 2018
           6 706   840   79   761   69   47  4352.062937062937 1694.1818181818182   9389.42444968187  2150.958041958042  2201.104895104895  760.4545  650.4685 1018.4406 2018
          19 706  1190   21  1169    2   72  5877.068027210885  2338.374149659864  9960.894555675277  2888.360544217687  2988.707482993197 1013.3605  919.2925  1301.204 2018
          27 706   479    7   472    0   37  4536.538461538462  1877.076923076923  12905.49243619401  2222.892307692308  2313.646153846154  660.1539   687.877 1136.6307 2018
          29 706 24785 1576 23209  381 2642 24539.127413127415  9817.548262548262   16362.5307050777 11746.011583011583  12793.11583011583  3757.023  3816.919  5517.765 2018
          48 706   734   29   705    4   58  5702.686046511628 2398.2906976744184 12815.065721142682 2764.8953488372094 2937.7906976744184  751.3372  791.7907 1555.1046 2018
           5 707 10646  389 10257  104  649 16504.891891891893  6633.318318318318 15940.840816623928  8052.375375375375  8452.516516516516 2470.5195 2563.5645  3944.027 2018
           6 707   898   23   875   13   44  4952.362903225807  1925.483870967742  9516.846348212153 2446.8225806451615 2505.5403225806454  864.4435  743.8951 1152.0887 2018
          19 707  1242   32  1210    4   90   5669.62987012987 2257.3896103896104  9961.990109645612 2787.4935064935066 2882.1363636363635  976.7922  882.8896 1261.4286 2018
          27 707   481   13   468    0   37 5188.8421052631575 2146.3508771929824  12955.86697079303 2541.5087719298244 2647.3333333333335  755.9298  788.3509 1299.9122 2018
          29 707 33405 2465 30940 1021 3107  25127.54761904762 10056.670634920634 16432.717980342593 12025.674603174602 13101.873015873016  3845.333  3906.627  5651.389 2018
          48 707   786   23   763    4   53  5940.682926829269  2501.890243902439 12741.190395454578 2879.5365853658536 3061.1463414634145  781.3415  825.1464 1621.2317 2018
           5 708 10556  366 10190   85  688 16590.459214501512   6668.45921450151 15879.266500562275  8093.722054380664  8496.737160120845  2483.332 2576.3474 3965.3474 2019
           6 708   709   11   698    3   66  4742.221374045802  1845.824427480916  9467.092117642858 2344.5419847328244  2397.679389312977  827.6641   712.374 1105.0763 2019
          19 708  1099   15  1084    2   89  5846.397260273972   2329.27397260274 10052.856702323363 2872.1643835616437 2974.2328767123286  1005.274  911.9932  1301.233 2019
          27 708   416    7   409    3   39  5072.206896551724  2099.448275862069  12971.29088089469  2484.810344827586  2587.396551724138  737.8276  771.7931 1269.3966 2019
          29 708 34135 1525 32610  330 3721 25574.072580645163 10233.229838709678  16512.58800804793 12239.862903225807 13334.209677419354 3914.9636   3977.77  5750.089 2019
          48 708   677   28   649    7   58  5809.940476190476 2443.0476190476193 12797.293501189843 2816.6190476190477 2993.3214285714284  765.7619  804.4643 1589.2738 2019
           5 709 10891  498 10393  170  746 16621.187311178248  6679.815709969788 15985.543514358746   8109.73413897281  8511.453172205438  2488.737  2582.402  3970.529 2019
           6 709   806    8   798    3   37  4572.328467153285 1780.2481751824816  9393.482892091717 2261.4671532846714 2310.8613138686133  798.1971  683.9489  1068.781 2019
          19 709  1063   17  1046    5   65  6072.288732394366 2414.8028169014083 10056.761205785468 2984.7323943661972  3087.556338028169 1048.3802     950.5 1341.3873 2019
          27 709   416    8   408    4   35  5395.574074074074 2228.6296296296296   13020.7834271943 2639.8333333333335  2755.740740740741  786.7778  823.1296  1345.537 2019
          29 709 38696 1619 37077  421 3628           25364.94          10149.888 16448.710606206376          12139.228          13225.712  3882.988  3944.348    5703.5 2019
          48 709   709   12   697    1   47  5398.516483516483  2271.032967032967 12744.513396023352 2617.6373626373625  2780.879120879121  711.7363  748.4945 1474.6483 2019
           5 710 13402  634 12768  297  949 16745.771341463416  6729.737804878048  15941.71582832849  8169.265243902439  8576.506097560976 2506.0305  2601.756 4001.1646 2019
           6 710   820   10   810    0   56  5459.954545454545 2121.5363636363636   9635.52043778995             2697.1 2762.8545454545456  951.6818  823.9909  1263.391 2019
          19 710  1255   28  1227    6  110  6057.347517730496 2408.0851063829787 10099.180646078858 2976.6028368794327  3080.744680851064 1044.1489  948.2341 1339.3263 2019
          27 710   446    5   441    4   45  5321.854545454546 2200.8545454545456 13135.008292688111             2604.6 2717.2545454545457     774.6  812.5273 1325.9818 2019
          29 710 47765 2102 45663  654 3788  24906.95294117647  9966.184313725491 16347.449789523687 11921.725490196079 12985.227450980392  3812.882  3873.529  5600.824 2019
          48 710   777   28   749    8   75  6107.113924050633 2569.0506329113923 13122.339471625522 2957.6075949367087  3149.506329113924  805.5443  850.6456  1661.228 2019
           5 711 11415  450 10965  118  931 16703.313069908814  6712.352583586626 15956.179781879899  8148.930091185411  8554.382978723404  2500.982  2595.067  3989.799 2019
           6 711   693   11   682    0   63               4907           1908.096  9500.345305310288            2425.08            2481.92   856.552    737.24  1141.288 2019
          19 711  1009   28   981    1   82  6315.171641791045  2512.276119402985 10146.333084904101  3102.007462686567 3213.1641791044776  1088.097   991.194  1391.224 2019
          27 711   356   11   345    1   30  5223.696428571428  2160.339285714286 13102.013830109117           2558.125 2665.5714285714284  760.3929  796.5893  1302.625 2019
          29 711 52053 1883 50170  329 3936 25561.104838709678 10230.677419354839  16385.51055513777 12233.504032258064 13327.600806451614  3911.968  3972.843  5750.383 2019
          48 711   682   19   663    3   59  5601.724137931034  2359.310344827586 12559.103142395177 2715.6206896551726  2886.103448275862  737.5632  776.3793 1530.6093 2019
          end
          format %tm moyr_matricula
          label values idprovdis idprovdis
          label def idprovdis 5 "B", modify
          label def idprovdis 6 "BA", modify
          label def idprovdis 19 "GR", modify
          label def idprovdis 27 "LO", modify
          label def idprovdis 29 "M", modify
          label def idprovdis 48 "VA", modify
          Last edited by Michael Duarte Goncalves; 02 Oct 2024, 03:28.

          Comment


          • #6
            And when I ran the following code on the sample above:

            Code:
                foreach a in HEV {
                    preserve
                    // ssc install synth2
                    gen `a' = (d_dum_`a'/tot)    
                    synth2 `a'  car_pct pp_euro hh_t frac_age_15to59 age_t1529 age_t0014 male ///
                        , trunit(29) trperiod(`=tm(2018m5)') xperiod(`=tm(2018m3)'(1)`=tm(2019m4)') nested
                    matrix R = e(U_wt)
                }
                    // ssc install mat2txt        
                    mat2txt, matrix(R) saving("${tables}/T2_`a'W.txt") replace format(%6.1f)
            
                    matrix R = e(bal)
                    matselrc R R1, row(1,2,3,4,5,6,7) col(1,2,3)
                    mat list R1 , format(%12.2f)
                    matmap R1 R, map(round(@, 0.001))
                    local att : di %6.3f  scalar(`e(att)')
                    di "`att'"
            
                    esttab matrix(R) using "${tables}/T2_baltab_`a'.tex",  ///
                        nomtitle replace nonote label booktabs star(* 0.10 ** 0.05 *** 0.01) ///
                        stats("`att'", labels("Avg effects: `att'") fmt(0 3 0 0))
                    restore
            I got the following error:

            Code:
            invalid syntax
            r(198);
            Last edited by Michael Duarte Goncalves; 02 Oct 2024, 03:27.

            Comment


            • #7
              Alright, when I get up in a half and make coffee I'll take a crack at this.


              By the way, just out of curiosity, what's this analysis about anyways

              Comment


              • #8
                Code:
                * Example generated by -dataex-. For more info, type help dataex
                clear
                input float idprovdis int moyr_matricula long tot int dum_ECO long dum_NONECO int(dum_ZERO dum_HEV) double(p_t hh_t pp_euro male female) float(age_t1529 age_t0014 age_t60pl year)
                 5 698 12803  445 12358  104  754 16319.816023738873  6559.581602373887 15916.311883765242  7962.323442136499  8357.492581602373 2442.7715  2534.994 3898.9614 2018
                 6 698   914    1   913    0   52  4689.248120300752 1825.0225563909773   9425.93074628905 2318.4887218045114 2370.7593984962405   818.218   702.015 1094.0828 2018
                19 698  1285   10  1275    1   87           6002.875  2388.215277777778 10048.051183823418 2950.9930555555557 3051.8819444444443 1034.6459  938.3055  1330.375 2018
                27 698   501    2   499    0   47  4670.190476190476 1935.1746031746031 12958.008543402206 2288.6825396825398 2381.5079365079364  677.7302  707.4603 1174.3016 2018
                29 698 49485  797 48688  183 2125 24370.555555555555  9750.570881226053 16354.604326224315 11666.019157088123 12704.536398467433 3731.1035  3790.444  5479.647 2018
                48 698   790   11   779    6   49  5554.136363636364 2338.1363636363635 12690.952611703658 2692.6704545454545  2861.465909090909       732  771.4432  1513.625 2018
                 5 699 12110  519 11591  114  822  16541.63253012048  6648.731927710844 15966.265943465127  8070.168674698795  8471.463855421687   2475.91 2570.3855  3951.253 2018
                 6 699   833   13   820    1   39               5019 1950.3801652892562   9519.27097521117 2480.2396694214876 2538.7603305785124  876.3471  755.2479 1164.2067 2018
                19 699  1318   13  1305    1   79            5820.28 2316.0666666666666  9978.469179244856            2862.04            2958.24 1002.9467  907.8267 1293.5734 2018
                27 699   459    4   455    1   33 5035.6551724137935  2082.689655172414 12937.483368257732 2463.0344827586205 2572.6206896551726  732.3793  768.8104 1254.1724 2018
                29 699 45255 1139 44116  174 2539 24998.267716535433 10001.448818897637 16448.441433000087  11965.13779527559 13033.129921259842  3828.205  3886.417  5622.453 2018
                48 699   733   15   718    5   50               5988 2516.5185185185187 12811.549995022013 2900.1234567901233 3087.8765432098767  792.9506  831.5926 1631.7037 2018
                 5 700 15069  617 14452   72  929  16665.60606060606  6697.721212121212 15977.868685685284  8130.878787878788  8534.727272727272  2494.203  2589.506  3981.373 2018
                 6 700   865    8   857    2   45 4882.1984126984125 1897.8174603174602  9507.031419551395 2412.9761904761904  2469.222222222222  854.1349  733.2222  1133.254 2018
                19 700  1351   14  1337    0   88  5863.163265306122  2332.598639455782 10048.499691949206 2881.9727891156463  2981.190476190476 1009.3062  916.9184  1297.374 2018
                27 700   525    6   519    0   38  4918.033333333334             2036.5 12990.762508797317 2409.2833333333333            2508.75     715.1     747.9 1230.2667 2018
                29 700 50289 1171 49118  132 3092  24534.14671814672  9816.181467181466  16426.38897442293 11743.710424710425 12790.436293436293  3756.297  3815.811  5515.645 2018
                48 700   797   18   779    0   76  6040.925925925926 2540.4444444444443 12944.507206990487 2929.1975308641977 3111.7283950617284  796.5803  839.5185  1645.074 2018
                 5 701 14020  556 13464   65  994  16217.10029498525 6517.0353982300885 15827.133560538923 7912.2684365781715   8304.83185840708 2426.8467  2519.283  3874.879 2018
                 6 701   928    9   919    1   30           4589.875 1785.9338235294117  9353.565051884838 2269.8970588235293 2319.9779411764707   800.728  688.6912 1070.7206 2018
                19 701  1355   21  1334    2   82  5832.216216216216  2317.391891891892 10009.632110877736 2866.9054054054054  2965.310810810811   1005.75  912.3649 1289.1554 2018
                27 701   529    3   526    0   33  5734.137254901961  2371.549019607843  13180.79175464488  2805.627450980392 2928.5098039215686  835.2549  875.0588 1428.5686 2018
                29 701 55469 1560 53909  182 4654 24634.422480620156  9854.813953488372 16432.322979194225 11791.267441860466  12843.15503875969  3772.205   3831.88  5538.771 2018
                48 701   807   19   788    1   44   5419.32967032967   2280.78021978022 12869.239684048645 2629.8241758241757 2789.5054945054944  713.1868  751.7582  1479.099 2018
                 5 702 15604  690 14914   82  898  16200.95588235294  6510.294117647059  15909.10105511216  7904.976470588235  8295.979411764705   2425.65  2517.029  3870.294 2018
                 6 702  1123    5  1118    0   58 4433.2535211267605 1724.7535211267605  9290.833565366207 2192.6619718309857 2240.5915492957747  774.5493  663.7253      1034 2018
                19 702  1487   24  1463    3   77  5830.790540540541  2319.635135135135 10009.812361854458 2866.9864864864867  2963.804054054054 1002.9054  911.3041 1293.5067 2018
                27 702   598    3   595    0   35  5227.160714285715 2159.9464285714284 13044.991219042244  2558.785714285714           2668.375  760.3214  795.1964 1306.5358 2018
                29 702 41710 1666 40044  217 3755 24900.972549019607  9963.184313725491 16399.558431590605 11918.392156862745 12982.580392156862  3812.408  3873.106  5598.945 2018
                48 702   955   15   940    4   51  5356.652173913043            2255.75 12640.791874081595 2597.8152173913045  2758.836956521739  705.8152  740.3587 1464.9022 2018
                 5 703 10605  345 10260   34  746 16542.683734939757  6648.656626506024 15873.592083394527   8070.69578313253  8471.987951807228  2476.274  2569.946  3951.976 2018
                 6 703   927    7   920    0   34  4594.462686567164  1784.858208955224  9378.004817972573 2271.5522388059703  2322.910447761194  803.4478  691.1716 1064.6791 2018
                19 703  1457   13  1444    0  100 5739.3708609271525 2285.3708609271525  9995.038375735761 2822.3576158940396 2917.0132450331125  988.4172  895.0662 1275.9602 2018
                27 703   504    3   501    0   35  4461.805970149254 1849.6119402985075 12877.919045242645 2188.9402985074626  2272.865671641791  647.4627  674.0448 1124.4329 2018
                29 703 32305 1730 30575  137 2222  25268.65338645418  10111.25498007968 16421.419702786403 12093.290836653387 13175.362549800797 3868.1475  3929.705  5682.104 2018
                48 703   883   13   870    2   64  6118.848101265823  2575.025316455696 12911.504388791162 2963.4177215189875 3155.4303797468356  806.8354  849.7342 1667.6582 2018
                 5 704  7922  343  7579   81  702 16938.956790123455  6807.049382716049  15950.26693640691  8263.225308641975  8675.731481481482   2536.12  2630.904  4048.028 2018
                 6 704   691    6   685    1   49           4830.384           1876.768    9434.6067346788           2387.184             2443.2    844.48    728.48  1117.712 2018
                19 704   906    9   897    5   62  6443.099236641221 2559.5648854961833 10166.699778344315 3162.7786259541986  3280.320610687023 1111.3359 1011.7405 1417.4275 2018
                27 704   344    4   340    0   27  5759.448979591837 2382.6326530612246 13259.241905579127 2813.6938775510203 2945.7551020408164  839.8163  879.8979  1429.306 2018
                29 704 18678  848 17830  248 2009 25575.798387096773  10232.95564516129 16476.577708557765 12240.108870967742 13335.689516129032  3915.617  3977.863  5751.653 2018
                48 704   562   11   551    1   50  6513.438356164384 2744.8630136986303 13166.199548379322 3151.5342465753424  3361.904109589041   855.863  909.6849 1769.5616 2018
                 5 705 10589  593  9996  120  862 16325.353115727003  6560.964391691395  15914.70090610372  7964.961424332344   8360.39169139466 2444.3176  2535.638  3901.024 2018
                 6 705   856   20   836    9   53  4664.087591240876  1816.043795620438  9422.150748349253  2307.058394160584  2357.029197080292   813.781  696.3431 1094.1825 2018
                19 705  1274   19  1255    0  118  5739.907284768212 2281.5099337748343  9947.858435898377 2822.0529801324506 2917.8543046357618  989.1259  896.8079  1271.437 2018
                27 705   456    6   450    0   45  4784.870967741936 1982.4516129032259 12979.695016186879  2344.951612903226 2439.9193548387098  694.9194  724.3065 1201.9839 2018
                29 705 24092 1371 22721  260 2714 24443.203846153847  9779.996153846154 16382.506235438746 11700.384615384615 12742.819230769232 3742.0884  3801.077      5497 2018
                48 705   658   29   629    8   46          6107.4375           2568.225 12930.896531367545             2959.9          3147.5375   806.275   849.175 1663.8125 2018
                 5 706 11713  356 11357   84  851  16568.91265060241  6657.993975903614 15945.860189138648  8083.512048192771  8485.400602409638  2480.434  2573.994 3959.3855 2018
                 6 706   840   79   761   69   47  4352.062937062937 1694.1818181818182   9389.42444968187  2150.958041958042  2201.104895104895  760.4545  650.4685 1018.4406 2018
                19 706  1190   21  1169    2   72  5877.068027210885  2338.374149659864  9960.894555675277  2888.360544217687  2988.707482993197 1013.3605  919.2925  1301.204 2018
                27 706   479    7   472    0   37  4536.538461538462  1877.076923076923  12905.49243619401  2222.892307692308  2313.646153846154  660.1539   687.877 1136.6307 2018
                29 706 24785 1576 23209  381 2642 24539.127413127415  9817.548262548262   16362.5307050777 11746.011583011583  12793.11583011583  3757.023  3816.919  5517.765 2018
                48 706   734   29   705    4   58  5702.686046511628 2398.2906976744184 12815.065721142682 2764.8953488372094 2937.7906976744184  751.3372  791.7907 1555.1046 2018
                 5 707 10646  389 10257  104  649 16504.891891891893  6633.318318318318 15940.840816623928  8052.375375375375  8452.516516516516 2470.5195 2563.5645  3944.027 2018
                 6 707   898   23   875   13   44  4952.362903225807  1925.483870967742  9516.846348212153 2446.8225806451615 2505.5403225806454  864.4435  743.8951 1152.0887 2018
                19 707  1242   32  1210    4   90   5669.62987012987 2257.3896103896104  9961.990109645612 2787.4935064935066 2882.1363636363635  976.7922  882.8896 1261.4286 2018
                27 707   481   13   468    0   37 5188.8421052631575 2146.3508771929824  12955.86697079303 2541.5087719298244 2647.3333333333335  755.9298  788.3509 1299.9122 2018
                29 707 33405 2465 30940 1021 3107  25127.54761904762 10056.670634920634 16432.717980342593 12025.674603174602 13101.873015873016  3845.333  3906.627  5651.389 2018
                48 707   786   23   763    4   53  5940.682926829269  2501.890243902439 12741.190395454578 2879.5365853658536 3061.1463414634145  781.3415  825.1464 1621.2317 2018
                 5 708 10556  366 10190   85  688 16590.459214501512   6668.45921450151 15879.266500562275  8093.722054380664  8496.737160120845  2483.332 2576.3474 3965.3474 2019
                 6 708   709   11   698    3   66  4742.221374045802  1845.824427480916  9467.092117642858 2344.5419847328244  2397.679389312977  827.6641   712.374 1105.0763 2019
                19 708  1099   15  1084    2   89  5846.397260273972   2329.27397260274 10052.856702323363 2872.1643835616437 2974.2328767123286  1005.274  911.9932  1301.233 2019
                27 708   416    7   409    3   39  5072.206896551724  2099.448275862069  12971.29088089469  2484.810344827586  2587.396551724138  737.8276  771.7931 1269.3966 2019
                29 708 34135 1525 32610  330 3721 25574.072580645163 10233.229838709678  16512.58800804793 12239.862903225807 13334.209677419354 3914.9636   3977.77  5750.089 2019
                48 708   677   28   649    7   58  5809.940476190476 2443.0476190476193 12797.293501189843 2816.6190476190477 2993.3214285714284  765.7619  804.4643 1589.2738 2019
                 5 709 10891  498 10393  170  746 16621.187311178248  6679.815709969788 15985.543514358746   8109.73413897281  8511.453172205438  2488.737  2582.402  3970.529 2019
                 6 709   806    8   798    3   37  4572.328467153285 1780.2481751824816  9393.482892091717 2261.4671532846714 2310.8613138686133  798.1971  683.9489  1068.781 2019
                19 709  1063   17  1046    5   65  6072.288732394366 2414.8028169014083 10056.761205785468 2984.7323943661972  3087.556338028169 1048.3802     950.5 1341.3873 2019
                27 709   416    8   408    4   35  5395.574074074074 2228.6296296296296   13020.7834271943 2639.8333333333335  2755.740740740741  786.7778  823.1296  1345.537 2019
                29 709 38696 1619 37077  421 3628           25364.94          10149.888 16448.710606206376          12139.228          13225.712  3882.988  3944.348    5703.5 2019
                48 709   709   12   697    1   47  5398.516483516483  2271.032967032967 12744.513396023352 2617.6373626373625  2780.879120879121  711.7363  748.4945 1474.6483 2019
                 5 710 13402  634 12768  297  949 16745.771341463416  6729.737804878048  15941.71582832849  8169.265243902439  8576.506097560976 2506.0305  2601.756 4001.1646 2019
                 6 710   820   10   810    0   56  5459.954545454545 2121.5363636363636   9635.52043778995             2697.1 2762.8545454545456  951.6818  823.9909  1263.391 2019
                19 710  1255   28  1227    6  110  6057.347517730496 2408.0851063829787 10099.180646078858 2976.6028368794327  3080.744680851064 1044.1489  948.2341 1339.3263 2019
                27 710   446    5   441    4   45  5321.854545454546 2200.8545454545456 13135.008292688111             2604.6 2717.2545454545457     774.6  812.5273 1325.9818 2019
                29 710 47765 2102 45663  654 3788  24906.95294117647  9966.184313725491 16347.449789523687 11921.725490196079 12985.227450980392  3812.882  3873.529  5600.824 2019
                48 710   777   28   749    8   75  6107.113924050633 2569.0506329113923 13122.339471625522 2957.6075949367087  3149.506329113924  805.5443  850.6456  1661.228 2019
                 5 711 11415  450 10965  118  931 16703.313069908814  6712.352583586626 15956.179781879899  8148.930091185411  8554.382978723404  2500.982  2595.067  3989.799 2019
                 6 711   693   11   682    0   63               4907           1908.096  9500.345305310288            2425.08            2481.92   856.552    737.24  1141.288 2019
                19 711  1009   28   981    1   82  6315.171641791045  2512.276119402985 10146.333084904101  3102.007462686567 3213.1641791044776  1088.097   991.194  1391.224 2019
                27 711   356   11   345    1   30  5223.696428571428  2160.339285714286 13102.013830109117           2558.125 2665.5714285714284  760.3929  796.5893  1302.625 2019
                29 711 52053 1883 50170  329 3936 25561.104838709678 10230.677419354839  16385.51055513777 12233.504032258064 13327.600806451614  3911.968  3972.843  5750.383 2019
                48 711   682   19   663    3   59  5601.724137931034  2359.310344827586 12559.103142395177 2715.6206896551726  2886.103448275862  737.5632  776.3793 1530.6093 2019
                end
                format %tm moyr_matricula
                label values idprovdis idprovdis
                label def idprovdis 5 "B", modify
                label def idprovdis 6 "BA", modify
                label def idprovdis 19 "GR", modify
                label def idprovdis 27 "LO", modify
                label def idprovdis 29 "M", modify
                label def idprovdis 48 "VA", modify
                xtset idprovdis moyr_matricula
                cls 
                
                    foreach a in HEV {
                        preserve
                        // ssc install synth2
                        gen `a' = (d_dum_`a'/tot)    
                        synth2 `a'  car_pct pp_euro hh_t frac_age_15to59 age_t1529 age_t0014 male ///
                            , trunit(29) trperiod(`=tm(2018m5)') xperiod(`=tm(2018m3)'(1)`=tm(2019m4)') nested
                        matrix R = e(U_wt)
                    }
                        // ssc install mat2txt        
                        mat2txt, matrix(R) saving("${tables}/T2_`a'W.txt") replace format(%6.1f)
                
                        matrix R = e(bal)
                        matselrc R R1, row(1,2,3,4,5,6,7) col(1,2,3)
                        mat list R1 , format(%12.2f)
                        matmap R1 R, map(round(@, 0.001))
                        local att : di %6.3f  scalar(`e(att)')
                        di "`att'"
                
                        esttab matrix(R) using "${tables}/T2_baltab_`a'.tex",  ///
                            nomtitle replace nonote label booktabs star(* 0.10 ** 0.05 *** 0.01) ///
                            stats("`att'", labels("Avg effects: `att'") fmt(0 3 0 0))
                        restore

                returns

                Code:
                .     foreach a in HEV {
                  2.         preserve
                  3.         // ssc install synth2
                .         gen `a' = (d_dum_`a'/tot)    
                  4.         synth2 `a'  car_pct pp_euro hh_t frac_age_15to59 age_t1529 age_t0014 male ///
                >             , trunit(29) trperiod(`=tm(2018m5)') xperiod(`=tm(2018m3)'(1)`=tm(2019m4)') nested
                  5.         matrix R = e(U_wt)
                  6.     }
                d_dum_HEV not found
                r(111);

                Comment


                • #9
                  Sorry again. I forgot to include those variables. Could you please try this one?

                  Code:
                  * Example generated by -dataex-. For more info, type help dataex
                  clear
                  input float idprovdis int moyr_matricula long tot int dum_ECO long dum_NONECO int dum_ZERO float(d_dum_HEV d_dum_ZERO) int dum_HEV double(p_t hh_t pp_euro male female) float(age_t1529 age_t0014 age_t60pl year)
                   5 698 12803  445 12358  104  651   85  754 16319.816023738873  6559.581602373887 15916.311883765242  7962.323442136499  8357.492581602373 2442.7715  2534.994 3898.9614 2018
                   6 698   914    1   913    0   52    0   52  4689.248120300752 1825.0225563909773   9425.93074628905 2318.4887218045114 2370.7593984962405   818.218   702.015 1094.0828 2018
                  19 698  1285   10  1275    1   83    1   87           6002.875  2388.215277777778 10048.051183823418 2950.9930555555557 3051.8819444444443 1034.6459  938.3055  1330.375 2018
                  27 698   501    2   499    0   42    0   47  4670.190476190476 1935.1746031746031 12958.008543402206 2288.6825396825398 2381.5079365079364  677.7302  707.4603 1174.3016 2018
                  29 698 49485  797 48688  183 1942  139 2125 24370.555555555555  9750.570881226053 16354.604326224315 11666.019157088123 12704.536398467433 3731.1035  3790.444  5479.647 2018
                  48 698   790   11   779    6   49    4   49  5554.136363636364 2338.1363636363635 12690.952611703658 2692.6704545454545  2861.465909090909       732  771.4432  1513.625 2018
                   5 699 12110  519 11591  114  720   92  822  16541.63253012048  6648.731927710844 15966.265943465127  8070.168674698795  8471.463855421687   2475.91 2570.3855  3951.253 2018
                   6 699   833   13   820    1   38    1   39               5019 1950.3801652892562   9519.27097521117 2480.2396694214876 2538.7603305785124  876.3471  755.2479 1164.2067 2018
                  19 699  1318   13  1305    1   75    1   79            5820.28 2316.0666666666666  9978.469179244856            2862.04            2958.24 1002.9467  907.8267 1293.5734 2018
                  27 699   459    4   455    1   28    1   33 5035.6551724137935  2082.689655172414 12937.483368257732 2463.0344827586205 2572.6206896551726  732.3793  768.8104 1254.1724 2018
                  29 699 45255 1139 44116  174 2384  156 2539 24998.267716535433 10001.448818897637 16448.441433000087  11965.13779527559 13033.129921259842  3828.205  3886.417  5622.453 2018
                  48 699   733   15   718    5   48    5   50               5988 2516.5185185185187 12811.549995022013 2900.1234567901233 3087.8765432098767  792.9506  831.5926 1631.7037 2018
                   5 700 15069  617 14452   72  844   61  929  16665.60606060606  6697.721212121212 15977.868685685284  8130.878787878788  8534.727272727272  2494.203  2589.506  3981.373 2018
                   6 700   865    8   857    2   43    2   45 4882.1984126984125 1897.8174603174602  9507.031419551395 2412.9761904761904  2469.222222222222  854.1349  733.2222  1133.254 2018
                  19 700  1351   14  1337    0   83    0   88  5863.163265306122  2332.598639455782 10048.499691949206 2881.9727891156463  2981.190476190476 1009.3062  916.9184  1297.374 2018
                  27 700   525    6   519    0   31    0   38  4918.033333333334             2036.5 12990.762508797317 2409.2833333333333            2508.75     715.1     747.9 1230.2667 2018
                  29 700 50289 1171 49118  132 2915  112 3092  24534.14671814672  9816.181467181466  16426.38897442293 11743.710424710425 12790.436293436293  3756.297  3815.811  5515.645 2018
                  48 700   797   18   779    0   74    0   76  6040.925925925926 2540.4444444444443 12944.507206990487 2929.1975308641977 3111.7283950617284  796.5803  839.5185  1645.074 2018
                   5 701 14020  556 13464   65  865   58  994  16217.10029498525 6517.0353982300885 15827.133560538923 7912.2684365781715   8304.83185840708 2426.8467  2519.283  3874.879 2018
                   6 701   928    9   919    1   30    1   30           4589.875 1785.9338235294117  9353.565051884838 2269.8970588235293 2319.9779411764707   800.728  688.6912 1070.7206 2018
                  19 701  1355   21  1334    2   79    2   82  5832.216216216216  2317.391891891892 10009.632110877736 2866.9054054054054  2965.310810810811   1005.75  912.3649 1289.1554 2018
                  27 701   529    3   526    0   26    0   33  5734.137254901961  2371.549019607843  13180.79175464488  2805.627450980392 2928.5098039215686  835.2549  875.0588 1428.5686 2018
                  29 701 55469 1560 53909  182 4471  144 4654 24634.422480620156  9854.813953488372 16432.322979194225 11791.267441860466  12843.15503875969  3772.205   3831.88  5538.771 2018
                  48 701   807   19   788    1   41    0   44   5419.32967032967   2280.78021978022 12869.239684048645 2629.8241758241757 2789.5054945054944  713.1868  751.7582  1479.099 2018
                   5 702 15604  690 14914   82  692   47  898  16200.95588235294  6510.294117647059  15909.10105511216  7904.976470588235  8295.979411764705   2425.65  2517.029  3870.294 2018
                   6 702  1123    5  1118    0   56    0   58 4433.2535211267605 1724.7535211267605  9290.833565366207 2192.6619718309857 2240.5915492957747  774.5493  663.7253      1034 2018
                  19 702  1487   24  1463    3   66    2   77  5830.790540540541  2319.635135135135 10009.812361854458 2866.9864864864867  2963.804054054054 1002.9054  911.3041 1293.5067 2018
                  27 702   598    3   595    0   18   -1   35  5227.160714285715 2159.9464285714284 13044.991219042244  2558.785714285714           2668.375  760.3214  795.1964 1306.5358 2018
                  29 702 41710 1666 40044  217 3472  195 3755 24900.972549019607  9963.184313725491 16399.558431590605 11918.392156862745 12982.580392156862  3812.408  3873.106  5598.945 2018
                  48 702   955   15   940    4   50    3   51  5356.652173913043            2255.75 12640.791874081595 2597.8152173913045  2758.836956521739  705.8152  740.3587 1464.9022 2018
                   5 703 10605  345 10260   34  631   20  746 16542.683734939757  6648.656626506024 15873.592083394527   8070.69578313253  8471.987951807228  2476.274  2569.946  3951.976 2018
                   6 703   927    7   920    0   28    0   34  4594.462686567164  1784.858208955224  9378.004817972573 2271.5522388059703  2322.910447761194  803.4478  691.1716 1064.6791 2018
                  19 703  1457   13  1444    0   94    0  100 5739.3708609271525 2285.3708609271525  9995.038375735761 2822.3576158940396 2917.0132450331125  988.4172  895.0662 1275.9602 2018
                  27 703   504    3   501    0   28   -1   35  4461.805970149254 1849.6119402985075 12877.919045242645 2188.9402985074626  2272.865671641791  647.4627  674.0448 1124.4329 2018
                  29 703 32305 1730 30575  137 2018  114 2222  25268.65338645418  10111.25498007968 16421.419702786403 12093.290836653387 13175.362549800797 3868.1475  3929.705  5682.104 2018
                  48 703   883   13   870    2   64    2   64  6118.848101265823  2575.025316455696 12911.504388791162 2963.4177215189875 3155.4303797468356  806.8354  849.7342 1667.6582 2018
                   5 704  7922  343  7579   81  492   63  702 16938.956790123455  6807.049382716049  15950.26693640691  8263.225308641975  8675.731481481482   2536.12  2630.904  4048.028 2018
                   6 704   691    6   685    1   42   -2   49           4830.384           1876.768    9434.6067346788           2387.184             2443.2    844.48    728.48  1117.712 2018
                  19 704   906    9   897    5   52    4   62  6443.099236641221 2559.5648854961833 10166.699778344315 3162.7786259541986  3280.320610687023 1111.3359 1011.7405 1417.4275 2018
                  27 704   344    4   340    0   15    0   27  5759.448979591837 2382.6326530612246 13259.241905579127 2813.6938775510203 2945.7551020408164  839.8163  879.8979  1429.306 2018
                  29 704 18678  848 17830  248 1720  227 2009 25575.798387096773  10232.95564516129 16476.577708557765 12240.108870967742 13335.689516129032  3915.617  3977.863  5751.653 2018
                  48 704   562   11   551    1   45    1   50  6513.438356164384 2744.8630136986303 13166.199548379322 3151.5342465753424  3361.904109589041   855.863  909.6849 1769.5616 2018
                   5 705 10589  593  9996  120  733   84  862 16325.353115727003  6560.964391691395  15914.70090610372  7964.961424332344   8360.39169139466 2444.3176  2535.638  3901.024 2018
                   6 705   856   20   836    9   53    9   53  4664.087591240876  1816.043795620438  9422.150748349253  2307.058394160584  2357.029197080292   813.781  696.3431 1094.1825 2018
                  19 705  1274   19  1255    0  112   -1  118  5739.907284768212 2281.5099337748343  9947.858435898377 2822.0529801324506 2917.8543046357618  989.1259  896.8079  1271.437 2018
                  27 705   456    6   450    0   36    0   45  4784.870967741936 1982.4516129032259 12979.695016186879  2344.951612903226 2439.9193548387098  694.9194  724.3065 1201.9839 2018
                  29 705 24092 1371 22721  260 2528   48 2714 24443.203846153847  9779.996153846154 16382.506235438746 11700.384615384615 12742.819230769232 3742.0884  3801.077      5497 2018
                  48 705   658   29   629    8   45    7   46          6107.4375           2568.225 12930.896531367545             2959.9          3147.5375   806.275   849.175 1663.8125 2018
                   5 706 11713  356 11357   84  836   78  851  16568.91265060241  6657.993975903614 15945.860189138648  8083.512048192771  8485.400602409638  2480.434  2573.994 3959.3855 2018
                   6 706   840   79   761   69   47   69   47  4352.062937062937 1694.1818181818182   9389.42444968187  2150.958041958042  2201.104895104895  760.4545  650.4685 1018.4406 2018
                  19 706  1190   21  1169    2   71    2   72  5877.068027210885  2338.374149659864  9960.894555675277  2888.360544217687  2988.707482993197 1013.3605  919.2925  1301.204 2018
                  27 706   479    7   472    0   37    0   37  4536.538461538462  1877.076923076923  12905.49243619401  2222.892307692308  2313.646153846154  660.1539   687.877 1136.6307 2018
                  29 706 24785 1576 23209  381 2590  212 2642 24539.127413127415  9817.548262548262   16362.5307050777 11746.011583011583  12793.11583011583  3757.023  3816.919  5517.765 2018
                  48 706   734   29   705    4   57    4   58  5702.686046511628 2398.2906976744184 12815.065721142682 2764.8953488372094 2937.7906976744184  751.3372  791.7907 1555.1046 2018
                   5 707 10646  389 10257  104  385   94  649 16504.891891891893  6633.318318318318 15940.840816623928  8052.375375375375  8452.516516516516 2470.5195 2563.5645  3944.027 2018
                   6 707   898   23   875   13   31   13   44  4952.362903225807  1925.483870967742  9516.846348212153 2446.8225806451615 2505.5403225806454  864.4435  743.8951 1152.0887 2018
                  19 707  1242   32  1210    4   68    4   90   5669.62987012987 2257.3896103896104  9961.990109645612 2787.4935064935066 2882.1363636363635  976.7922  882.8896 1261.4286 2018
                  27 707   481   13   468    0   26    0   37 5188.8421052631575 2146.3508771929824  12955.86697079303 2541.5087719298244 2647.3333333333335  755.9298  788.3509 1299.9122 2018
                  29 707 33405 2465 30940 1021 2732 1009 3107  25127.54761904762 10056.670634920634 16432.717980342593 12025.674603174602 13101.873015873016  3845.333  3906.627  5651.389 2018
                  48 707   786   23   763    4   40    4   53  5940.682926829269  2501.890243902439 12741.190395454578 2879.5365853658536 3061.1463414634145  781.3415  825.1464 1621.2317 2018
                   5 708 10556  366 10190   85  606   71  688 16590.459214501512   6668.45921450151 15879.266500562275  8093.722054380664  8496.737160120845  2483.332 2576.3474 3965.3474 2019
                   6 708   709   11   698    3   65    3   66  4742.221374045802  1845.824427480916  9467.092117642858 2344.5419847328244  2397.679389312977  827.6641   712.374 1105.0763 2019
                  19 708  1099   15  1084    2   85    2   89  5846.397260273972   2329.27397260274 10052.856702323363 2872.1643835616437 2974.2328767123286  1005.274  911.9932  1301.233 2019
                  27 708   416    7   409    3   30    3   39  5072.206896551724  2099.448275862069  12971.29088089469  2484.810344827586  2587.396551724138  737.8276  771.7931 1269.3966 2019
                  29 708 34135 1525 32610  330 3565  321 3721 25574.072580645163 10233.229838709678  16512.58800804793 12239.862903225807 13334.209677419354 3914.9636   3977.77  5750.089 2019
                  48 708   677   28   649    7   56    7   58  5809.940476190476 2443.0476190476193 12797.293501189843 2816.6190476190477 2993.3214285714284  765.7619  804.4643 1589.2738 2019
                   5 709 10891  498 10393  170  681  164  746 16621.187311178248  6679.815709969788 15985.543514358746   8109.73413897281  8511.453172205438  2488.737  2582.402  3970.529 2019
                   6 709   806    8   798    3   36    3   37  4572.328467153285 1780.2481751824816  9393.482892091717 2261.4671532846714 2310.8613138686133  798.1971  683.9489  1068.781 2019
                  19 709  1063   17  1046    5   61    5   65  6072.288732394366 2414.8028169014083 10056.761205785468 2984.7323943661972  3087.556338028169 1048.3802     950.5 1341.3873 2019
                  27 709   416    8   408    4   32    4   35  5395.574074074074 2228.6296296296296   13020.7834271943 2639.8333333333335  2755.740740740741  786.7778  823.1296  1345.537 2019
                  29 709 38696 1619 37077  421 3508  411 3628           25364.94          10149.888 16448.710606206376          12139.228          13225.712  3882.988  3944.348    5703.5 2019
                  48 709   709   12   697    1   47    1   47  5398.516483516483  2271.032967032967 12744.513396023352 2617.6373626373625  2780.879120879121  711.7363  748.4945 1474.6483 2019
                   5 710 13402  634 12768  297  846  278  949 16745.771341463416  6729.737804878048  15941.71582832849  8169.265243902439  8576.506097560976 2506.0305  2601.756 4001.1646 2019
                   6 710   820   10   810    0   56    0   56  5459.954545454545 2121.5363636363636   9635.52043778995             2697.1 2762.8545454545456  951.6818  823.9909  1263.391 2019
                  19 710  1255   28  1227    6  106    6  110  6057.347517730496 2408.0851063829787 10099.180646078858 2976.6028368794327  3080.744680851064 1044.1489  948.2341 1339.3263 2019
                  27 710   446    5   441    4   40    4   45  5321.854545454546 2200.8545454545456 13135.008292688111             2604.6 2717.2545454545457     774.6  812.5273 1325.9818 2019
                  29 710 47765 2102 45663  654 3605  610 3788  24906.95294117647  9966.184313725491 16347.449789523687 11921.725490196079 12985.227450980392  3812.882  3873.529  5600.824 2019
                  48 710   777   28   749    8   75    6   75  6107.113924050633 2569.0506329113923 13122.339471625522 2957.6075949367087  3149.506329113924  805.5443  850.6456  1661.228 2019
                   5 711 11415  450 10965  118  829   96  931 16703.313069908814  6712.352583586626 15956.179781879899  8148.930091185411  8554.382978723404  2500.982  2595.067  3989.799 2019
                   6 711   693   11   682    0   62    0   63               4907           1908.096  9500.345305310288            2425.08            2481.92   856.552    737.24  1141.288 2019
                  19 711  1009   28   981    1   78    1   82  6315.171641791045  2512.276119402985 10146.333084904101  3102.007462686567 3213.1641791044776  1088.097   991.194  1391.224 2019
                  27 711   356   11   345    1   25    1   30  5223.696428571428  2160.339285714286 13102.013830109117           2558.125 2665.5714285714284  760.3929  796.5893  1302.625 2019
                  29 711 52053 1883 50170  329 3781  311 3936 25561.104838709678 10230.677419354839  16385.51055513777 12233.504032258064 13327.600806451614  3911.968  3972.843  5750.383 2019
                  48 711   682   19   663    3   57    3   59  5601.724137931034  2359.310344827586 12559.103142395177 2715.6206896551726  2886.103448275862  737.5632  776.3793 1530.6093 2019
                  end
                  format %tm moyr_matricula
                  label values idprovdis idprovdis
                  label def idprovdis 5 "B", modify
                  label def idprovdis 6 "BA", modify
                  label def idprovdis 19 "GR", modify
                  label def idprovdis 27 "LO", modify
                  label def idprovdis 29 "M", modify
                  label def idprovdis 48 "VA", modify

                  Thank you again for your help. And sorry about the typo.

                  Comment


                  • #10
                    Originally posted by Jared Greathouse View Post
                    Alright, when I get up in a half and make coffee I'll take a crack at this.


                    By the way, just out of curiosity, what's this analysis about anyways

                    We would like to estimate the impact of the introduction of a Low Emissions Zone (LEZ) in Madrid, Spain, from May 2018 onwards, on the adoption of new electric vehicles and hybrid ones.

                    For this we would like to use a synthetic control, and a model inspired by Grieco et al (2024). The link is here: Evolution of Market Power in the U.S. Automobile Industry* | The Quarterly Journal of Economics | Oxford Academic (oup.com)

                    Thank you very much for your help.

                    Comment


                    • #11
                      Very well. Here is what I get

                      Code:
                      * Example generated by -dataex-. For more info, type help dataex
                      clear
                      input float idprovdis int moyr_matricula long tot int dum_ECO long dum_NONECO int dum_ZERO float(d_dum_HEV d_dum_ZERO) int dum_HEV double(p_t hh_t pp_euro male female) float(age_t1529 age_t0014 age_t60pl year)
                       5 698 12803  445 12358  104  651   85  754 16319.816023738873  6559.581602373887 15916.311883765242  7962.323442136499  8357.492581602373 2442.7715  2534.994 3898.9614 2018
                       6 698   914    1   913    0   52    0   52  4689.248120300752 1825.0225563909773   9425.93074628905 2318.4887218045114 2370.7593984962405   818.218   702.015 1094.0828 2018
                      19 698  1285   10  1275    1   83    1   87           6002.875  2388.215277777778 10048.051183823418 2950.9930555555557 3051.8819444444443 1034.6459  938.3055  1330.375 2018
                      27 698   501    2   499    0   42    0   47  4670.190476190476 1935.1746031746031 12958.008543402206 2288.6825396825398 2381.5079365079364  677.7302  707.4603 1174.3016 2018
                      29 698 49485  797 48688  183 1942  139 2125 24370.555555555555  9750.570881226053 16354.604326224315 11666.019157088123 12704.536398467433 3731.1035  3790.444  5479.647 2018
                      48 698   790   11   779    6   49    4   49  5554.136363636364 2338.1363636363635 12690.952611703658 2692.6704545454545  2861.465909090909       732  771.4432  1513.625 2018
                       5 699 12110  519 11591  114  720   92  822  16541.63253012048  6648.731927710844 15966.265943465127  8070.168674698795  8471.463855421687   2475.91 2570.3855  3951.253 2018
                       6 699   833   13   820    1   38    1   39               5019 1950.3801652892562   9519.27097521117 2480.2396694214876 2538.7603305785124  876.3471  755.2479 1164.2067 2018
                      19 699  1318   13  1305    1   75    1   79            5820.28 2316.0666666666666  9978.469179244856            2862.04            2958.24 1002.9467  907.8267 1293.5734 2018
                      27 699   459    4   455    1   28    1   33 5035.6551724137935  2082.689655172414 12937.483368257732 2463.0344827586205 2572.6206896551726  732.3793  768.8104 1254.1724 2018
                      29 699 45255 1139 44116  174 2384  156 2539 24998.267716535433 10001.448818897637 16448.441433000087  11965.13779527559 13033.129921259842  3828.205  3886.417  5622.453 2018
                      48 699   733   15   718    5   48    5   50               5988 2516.5185185185187 12811.549995022013 2900.1234567901233 3087.8765432098767  792.9506  831.5926 1631.7037 2018
                       5 700 15069  617 14452   72  844   61  929  16665.60606060606  6697.721212121212 15977.868685685284  8130.878787878788  8534.727272727272  2494.203  2589.506  3981.373 2018
                       6 700   865    8   857    2   43    2   45 4882.1984126984125 1897.8174603174602  9507.031419551395 2412.9761904761904  2469.222222222222  854.1349  733.2222  1133.254 2018
                      19 700  1351   14  1337    0   83    0   88  5863.163265306122  2332.598639455782 10048.499691949206 2881.9727891156463  2981.190476190476 1009.3062  916.9184  1297.374 2018
                      27 700   525    6   519    0   31    0   38  4918.033333333334             2036.5 12990.762508797317 2409.2833333333333            2508.75     715.1     747.9 1230.2667 2018
                      29 700 50289 1171 49118  132 2915  112 3092  24534.14671814672  9816.181467181466  16426.38897442293 11743.710424710425 12790.436293436293  3756.297  3815.811  5515.645 2018
                      48 700   797   18   779    0   74    0   76  6040.925925925926 2540.4444444444443 12944.507206990487 2929.1975308641977 3111.7283950617284  796.5803  839.5185  1645.074 2018
                       5 701 14020  556 13464   65  865   58  994  16217.10029498525 6517.0353982300885 15827.133560538923 7912.2684365781715   8304.83185840708 2426.8467  2519.283  3874.879 2018
                       6 701   928    9   919    1   30    1   30           4589.875 1785.9338235294117  9353.565051884838 2269.8970588235293 2319.9779411764707   800.728  688.6912 1070.7206 2018
                      19 701  1355   21  1334    2   79    2   82  5832.216216216216  2317.391891891892 10009.632110877736 2866.9054054054054  2965.310810810811   1005.75  912.3649 1289.1554 2018
                      27 701   529    3   526    0   26    0   33  5734.137254901961  2371.549019607843  13180.79175464488  2805.627450980392 2928.5098039215686  835.2549  875.0588 1428.5686 2018
                      29 701 55469 1560 53909  182 4471  144 4654 24634.422480620156  9854.813953488372 16432.322979194225 11791.267441860466  12843.15503875969  3772.205   3831.88  5538.771 2018
                      48 701   807   19   788    1   41    0   44   5419.32967032967   2280.78021978022 12869.239684048645 2629.8241758241757 2789.5054945054944  713.1868  751.7582  1479.099 2018
                       5 702 15604  690 14914   82  692   47  898  16200.95588235294  6510.294117647059  15909.10105511216  7904.976470588235  8295.979411764705   2425.65  2517.029  3870.294 2018
                       6 702  1123    5  1118    0   56    0   58 4433.2535211267605 1724.7535211267605  9290.833565366207 2192.6619718309857 2240.5915492957747  774.5493  663.7253      1034 2018
                      19 702  1487   24  1463    3   66    2   77  5830.790540540541  2319.635135135135 10009.812361854458 2866.9864864864867  2963.804054054054 1002.9054  911.3041 1293.5067 2018
                      27 702   598    3   595    0   18   -1   35  5227.160714285715 2159.9464285714284 13044.991219042244  2558.785714285714           2668.375  760.3214  795.1964 1306.5358 2018
                      29 702 41710 1666 40044  217 3472  195 3755 24900.972549019607  9963.184313725491 16399.558431590605 11918.392156862745 12982.580392156862  3812.408  3873.106  5598.945 2018
                      48 702   955   15   940    4   50    3   51  5356.652173913043            2255.75 12640.791874081595 2597.8152173913045  2758.836956521739  705.8152  740.3587 1464.9022 2018
                       5 703 10605  345 10260   34  631   20  746 16542.683734939757  6648.656626506024 15873.592083394527   8070.69578313253  8471.987951807228  2476.274  2569.946  3951.976 2018
                       6 703   927    7   920    0   28    0   34  4594.462686567164  1784.858208955224  9378.004817972573 2271.5522388059703  2322.910447761194  803.4478  691.1716 1064.6791 2018
                      19 703  1457   13  1444    0   94    0  100 5739.3708609271525 2285.3708609271525  9995.038375735761 2822.3576158940396 2917.0132450331125  988.4172  895.0662 1275.9602 2018
                      27 703   504    3   501    0   28   -1   35  4461.805970149254 1849.6119402985075 12877.919045242645 2188.9402985074626  2272.865671641791  647.4627  674.0448 1124.4329 2018
                      29 703 32305 1730 30575  137 2018  114 2222  25268.65338645418  10111.25498007968 16421.419702786403 12093.290836653387 13175.362549800797 3868.1475  3929.705  5682.104 2018
                      48 703   883   13   870    2   64    2   64  6118.848101265823  2575.025316455696 12911.504388791162 2963.4177215189875 3155.4303797468356  806.8354  849.7342 1667.6582 2018
                       5 704  7922  343  7579   81  492   63  702 16938.956790123455  6807.049382716049  15950.26693640691  8263.225308641975  8675.731481481482   2536.12  2630.904  4048.028 2018
                       6 704   691    6   685    1   42   -2   49           4830.384           1876.768    9434.6067346788           2387.184             2443.2    844.48    728.48  1117.712 2018
                      19 704   906    9   897    5   52    4   62  6443.099236641221 2559.5648854961833 10166.699778344315 3162.7786259541986  3280.320610687023 1111.3359 1011.7405 1417.4275 2018
                      27 704   344    4   340    0   15    0   27  5759.448979591837 2382.6326530612246 13259.241905579127 2813.6938775510203 2945.7551020408164  839.8163  879.8979  1429.306 2018
                      29 704 18678  848 17830  248 1720  227 2009 25575.798387096773  10232.95564516129 16476.577708557765 12240.108870967742 13335.689516129032  3915.617  3977.863  5751.653 2018
                      48 704   562   11   551    1   45    1   50  6513.438356164384 2744.8630136986303 13166.199548379322 3151.5342465753424  3361.904109589041   855.863  909.6849 1769.5616 2018
                       5 705 10589  593  9996  120  733   84  862 16325.353115727003  6560.964391691395  15914.70090610372  7964.961424332344   8360.39169139466 2444.3176  2535.638  3901.024 2018
                       6 705   856   20   836    9   53    9   53  4664.087591240876  1816.043795620438  9422.150748349253  2307.058394160584  2357.029197080292   813.781  696.3431 1094.1825 2018
                      19 705  1274   19  1255    0  112   -1  118  5739.907284768212 2281.5099337748343  9947.858435898377 2822.0529801324506 2917.8543046357618  989.1259  896.8079  1271.437 2018
                      27 705   456    6   450    0   36    0   45  4784.870967741936 1982.4516129032259 12979.695016186879  2344.951612903226 2439.9193548387098  694.9194  724.3065 1201.9839 2018
                      29 705 24092 1371 22721  260 2528   48 2714 24443.203846153847  9779.996153846154 16382.506235438746 11700.384615384615 12742.819230769232 3742.0884  3801.077      5497 2018
                      48 705   658   29   629    8   45    7   46          6107.4375           2568.225 12930.896531367545             2959.9          3147.5375   806.275   849.175 1663.8125 2018
                       5 706 11713  356 11357   84  836   78  851  16568.91265060241  6657.993975903614 15945.860189138648  8083.512048192771  8485.400602409638  2480.434  2573.994 3959.3855 2018
                       6 706   840   79   761   69   47   69   47  4352.062937062937 1694.1818181818182   9389.42444968187  2150.958041958042  2201.104895104895  760.4545  650.4685 1018.4406 2018
                      19 706  1190   21  1169    2   71    2   72  5877.068027210885  2338.374149659864  9960.894555675277  2888.360544217687  2988.707482993197 1013.3605  919.2925  1301.204 2018
                      27 706   479    7   472    0   37    0   37  4536.538461538462  1877.076923076923  12905.49243619401  2222.892307692308  2313.646153846154  660.1539   687.877 1136.6307 2018
                      29 706 24785 1576 23209  381 2590  212 2642 24539.127413127415  9817.548262548262   16362.5307050777 11746.011583011583  12793.11583011583  3757.023  3816.919  5517.765 2018
                      48 706   734   29   705    4   57    4   58  5702.686046511628 2398.2906976744184 12815.065721142682 2764.8953488372094 2937.7906976744184  751.3372  791.7907 1555.1046 2018
                       5 707 10646  389 10257  104  385   94  649 16504.891891891893  6633.318318318318 15940.840816623928  8052.375375375375  8452.516516516516 2470.5195 2563.5645  3944.027 2018
                       6 707   898   23   875   13   31   13   44  4952.362903225807  1925.483870967742  9516.846348212153 2446.8225806451615 2505.5403225806454  864.4435  743.8951 1152.0887 2018
                      19 707  1242   32  1210    4   68    4   90   5669.62987012987 2257.3896103896104  9961.990109645612 2787.4935064935066 2882.1363636363635  976.7922  882.8896 1261.4286 2018
                      27 707   481   13   468    0   26    0   37 5188.8421052631575 2146.3508771929824  12955.86697079303 2541.5087719298244 2647.3333333333335  755.9298  788.3509 1299.9122 2018
                      29 707 33405 2465 30940 1021 2732 1009 3107  25127.54761904762 10056.670634920634 16432.717980342593 12025.674603174602 13101.873015873016  3845.333  3906.627  5651.389 2018
                      48 707   786   23   763    4   40    4   53  5940.682926829269  2501.890243902439 12741.190395454578 2879.5365853658536 3061.1463414634145  781.3415  825.1464 1621.2317 2018
                       5 708 10556  366 10190   85  606   71  688 16590.459214501512   6668.45921450151 15879.266500562275  8093.722054380664  8496.737160120845  2483.332 2576.3474 3965.3474 2019
                       6 708   709   11   698    3   65    3   66  4742.221374045802  1845.824427480916  9467.092117642858 2344.5419847328244  2397.679389312977  827.6641   712.374 1105.0763 2019
                      19 708  1099   15  1084    2   85    2   89  5846.397260273972   2329.27397260274 10052.856702323363 2872.1643835616437 2974.2328767123286  1005.274  911.9932  1301.233 2019
                      27 708   416    7   409    3   30    3   39  5072.206896551724  2099.448275862069  12971.29088089469  2484.810344827586  2587.396551724138  737.8276  771.7931 1269.3966 2019
                      29 708 34135 1525 32610  330 3565  321 3721 25574.072580645163 10233.229838709678  16512.58800804793 12239.862903225807 13334.209677419354 3914.9636   3977.77  5750.089 2019
                      48 708   677   28   649    7   56    7   58  5809.940476190476 2443.0476190476193 12797.293501189843 2816.6190476190477 2993.3214285714284  765.7619  804.4643 1589.2738 2019
                       5 709 10891  498 10393  170  681  164  746 16621.187311178248  6679.815709969788 15985.543514358746   8109.73413897281  8511.453172205438  2488.737  2582.402  3970.529 2019
                       6 709   806    8   798    3   36    3   37  4572.328467153285 1780.2481751824816  9393.482892091717 2261.4671532846714 2310.8613138686133  798.1971  683.9489  1068.781 2019
                      19 709  1063   17  1046    5   61    5   65  6072.288732394366 2414.8028169014083 10056.761205785468 2984.7323943661972  3087.556338028169 1048.3802     950.5 1341.3873 2019
                      27 709   416    8   408    4   32    4   35  5395.574074074074 2228.6296296296296   13020.7834271943 2639.8333333333335  2755.740740740741  786.7778  823.1296  1345.537 2019
                      29 709 38696 1619 37077  421 3508  411 3628           25364.94          10149.888 16448.710606206376          12139.228          13225.712  3882.988  3944.348    5703.5 2019
                      48 709   709   12   697    1   47    1   47  5398.516483516483  2271.032967032967 12744.513396023352 2617.6373626373625  2780.879120879121  711.7363  748.4945 1474.6483 2019
                       5 710 13402  634 12768  297  846  278  949 16745.771341463416  6729.737804878048  15941.71582832849  8169.265243902439  8576.506097560976 2506.0305  2601.756 4001.1646 2019
                       6 710   820   10   810    0   56    0   56  5459.954545454545 2121.5363636363636   9635.52043778995             2697.1 2762.8545454545456  951.6818  823.9909  1263.391 2019
                      19 710  1255   28  1227    6  106    6  110  6057.347517730496 2408.0851063829787 10099.180646078858 2976.6028368794327  3080.744680851064 1044.1489  948.2341 1339.3263 2019
                      27 710   446    5   441    4   40    4   45  5321.854545454546 2200.8545454545456 13135.008292688111             2604.6 2717.2545454545457     774.6  812.5273 1325.9818 2019
                      29 710 47765 2102 45663  654 3605  610 3788  24906.95294117647  9966.184313725491 16347.449789523687 11921.725490196079 12985.227450980392  3812.882  3873.529  5600.824 2019
                      48 710   777   28   749    8   75    6   75  6107.113924050633 2569.0506329113923 13122.339471625522 2957.6075949367087  3149.506329113924  805.5443  850.6456  1661.228 2019
                       5 711 11415  450 10965  118  829   96  931 16703.313069908814  6712.352583586626 15956.179781879899  8148.930091185411  8554.382978723404  2500.982  2595.067  3989.799 2019
                       6 711   693   11   682    0   62    0   63               4907           1908.096  9500.345305310288            2425.08            2481.92   856.552    737.24  1141.288 2019
                      19 711  1009   28   981    1   78    1   82  6315.171641791045  2512.276119402985 10146.333084904101  3102.007462686567 3213.1641791044776  1088.097   991.194  1391.224 2019
                      27 711   356   11   345    1   25    1   30  5223.696428571428  2160.339285714286 13102.013830109117           2558.125 2665.5714285714284  760.3929  796.5893  1302.625 2019
                      29 711 52053 1883 50170  329 3781  311 3936 25561.104838709678 10230.677419354839  16385.51055513777 12233.504032258064 13327.600806451614  3911.968  3972.843  5750.383 2019
                      48 711   682   19   663    3   57    3   59  5601.724137931034  2359.310344827586 12559.103142395177 2715.6206896551726  2886.103448275862  737.5632  776.3793 1530.6093 2019
                      end
                      format %tm moyr_matricula
                      label values idprovdis idprovdis
                      label def idprovdis 5 "B", modify
                      label def idprovdis 6 "BA", modify
                      label def idprovdis 19 "GR", modify
                      label def idprovdis 27 "LO", modify
                      label def idprovdis 29 "M", modify
                      label def idprovdis 48 "VA", modify
                      
                      
                      xtset idprovdis moyr_matricula
                      cls 
                      set tr off
                          foreach a in HEV {
                              preserve
                              // ssc install synth2
                              gen `a' = (d_dum_`a'/tot)    
                              synth2 `a'  car_pct pp_euro hh_t frac_age_15to59 age_t1529 age_t0014 male ///
                                  , trunit(29) trperiod(`=tm(2018m5)') xperiod(`=tm(2018m3)'(1)`=tm(2019m4)') nested
                              matrix R = e(U_wt)
                          }
                              // ssc install mat2txt        
                              mat2txt, matrix(R) saving("${tables}/T2_`a'W.txt") replace format(%6.1f)
                      
                              matrix R = e(bal)
                              matselrc R R1, row(1,2,3,4,5,6,7) col(1,2,3)
                              mat list R1 , format(%12.2f)
                              matmap R1 R, map(round(@, 0.001))
                              local att : di %6.3f  scalar(`e(att)')
                              di "`att'"
                      
                              esttab matrix(R) using "${tables}/T2_baltab_`a'.tex",  ///
                                  nomtitle replace nonote label booktabs star(* 0.10 ** 0.05 *** 0.01) ///
                                  stats("`att'", labels("Avg effects: `att'") fmt(0 3 0 0))
                              restore
                      So now we're getting somewhere. When I switched to normal synth, Stata tells me

                      Code:
                      -------------------------------------------------------------------------------------------------------------------------------------------------
                      Synthetic Control Method for Comparative Case Studies
                      -------------------------------------------------------------------------------------------------------------------------------------------------
                      
                      First Step: Data Setup
                      -------------------------------------------------------------------------------------------------------------------------------------------------
                      car_pct does not exist as a (numeric) variable in dataset
                      r(198);
                      By the way, just out of curiosity, who wrote this code? Does it in part come from the paper you've linked?

                      Comment


                      • #12
                        Originally posted by Jared Greathouse View Post
                        By the way, just out of curiosity, who wrote this code? Does it in part come from the paper you've linked?
                        The code was written by an ex-pre doc, if I am not mistaken. This code was provided to me by a Professor.
                        The code does not come from the attached paper.

                        Thank you for your help on that.

                        Comment


                        • #13
                          Originally posted by Jared Greathouse View Post
                          So now we're getting somewhere. When I switched to normal synth, Stata tells me

                          Code:
                          -------------------------------------------------------------------------------------------------------------------------------------------------
                          Synthetic Control Method for Comparative Case Studies
                          -------------------------------------------------------------------------------------------------------------------------------------------------
                          
                          First Step: Data Setup
                          -------------------------------------------------------------------------------------------------------------------------------------------------
                          car_pct does not exist as a (numeric) variable in dataset
                          r(198);
                          By the way, just out of curiosity, who wrote this code? Does it in part come from the paper you've linked?
                          But the variable car_pct is a float one. So why is it not distinguished as a numeric variable, then?

                          Thank you

                          Comment


                          • #14
                            Okay. I do not think they knew what they were doing. Here is why. Look at this part of the code


                            Code:
                            trperiod(`=tm(2018m5)') xperiod(`=tm(2018m3)'(1)`=tm(2019m4)')
                            Treatment begins in May of 2018. Okay cool. But they average their predictor variables in the construction of the synthetic control to be in the post intervention period. See how they average the variables from March 2018 to April 2019? That includes the post-intervention period!!! You'll get the wrong results that way since you're averaging over your post-intervention covariates, instead you must average over the pre-period only.

                            From the help for synth:

                            xperiod(numlist) a list of time periods over which the predictor variables specified in predictorvars are averaged. The list of time periods refers to the panel time variable specified in tsset timevar. For example, if the specified panel time variable is given in years, xperiod(1980(1)1988) indicates that the predictor variables are averaged over all years from 1980, 1981,...,1988. See numlist on how to specify lists of numbers.

                            Edit for #13:


                            Stata is telling you

                            car_pct does not exist as a (numeric) variable in dataset
                            that is, the variable is not in the data example.
                            Last edited by Jared Greathouse; 02 Oct 2024, 07:10.

                            Comment


                            • #15
                              Edit for #13:


                              Stata is telling you

                              car_pct does not exist as a (numeric) variable in dataset
                              that is, the variable is not in the data example.
                              Ok. I have created it. It should be in this sample now:

                              Code:
                              * Example generated by -dataex-. For more info, type help dataex
                              clear
                              input float idprovdis int moyr_matricula long tot int dum_ECO long dum_NONECO int dum_ZERO float(d_dum_HEV d_dum_ZERO) int dum_HEV double(p_t hh_t pp_euro male female) float(age_t1529 age_t0014 age_t60pl year car_pct)
                               5 698 12803  445 12358  104  651   85  754 16319.816023738873  6559.581602373887 15916.311883765242  7962.323442136499  8357.492581602373 2442.7715  2534.994 3898.9614 2018   .7845064
                               6 698   914    1   913    0   52    0   52  4689.248120300752 1825.0225563909773   9425.93074628905 2318.4887218045114 2370.7593984962405   818.218   702.015 1094.0828 2018    .194914
                              19 698  1285   10  1275    1   83    1   87           6002.875  2388.215277777778 10048.051183823418 2950.9930555555557 3051.8819444444443 1034.6459  938.3055  1330.375 2018   .2140641
                              27 698   501    2   499    0   42    0   47  4670.190476190476 1935.1746031746031 12958.008543402206 2288.6825396825398 2381.5079365079364  677.7302  707.4603 1174.3016 2018  .10727614
                              29 698 49485  797 48688  183 1942  139 2125 24370.555555555555  9750.570881226053 16354.604326224315 11666.019157088123 12704.536398467433 3731.1035  3790.444  5479.647 2018   2.030524
                              48 698   790   11   779    6   49    4   49  5554.136363636364 2338.1363636363635 12690.952611703658 2692.6704545454545  2861.465909090909       732  771.4432  1513.625 2018  .14223634
                               5 699 12110  519 11591  114  720   92  822  16541.63253012048  6648.731927710844 15966.265943465127  8070.168674698795  8471.463855421687   2475.91 2570.3855  3951.253 2018   .7320922
                               6 699   833   13   820    1   38    1   39               5019 1950.3801652892562   9519.27097521117 2480.2396694214876 2538.7603305785124  876.3471  755.2479 1164.2067 2018   .1659693
                              19 699  1318   13  1305    1   75    1   79            5820.28 2316.0666666666666  9978.469179244856            2862.04            2958.24 1002.9467  907.8267 1293.5734 2018   .2264496
                              27 699   459    4   455    1   28    1   33 5035.6551724137935  2082.689655172414 12937.483368257732 2463.0344827586205 2572.6206896551726  732.3793  768.8104 1254.1724 2018     .09115
                              29 699 45255 1139 44116  174 2384  156 2539 24998.267716535433 10001.448818897637 16448.441433000087  11965.13779527559 13033.129921259842  3828.205  3886.417  5622.453 2018  1.8103254
                              48 699   733   15   718    5   48    5   50               5988 2516.5185185185187 12811.549995022013 2900.1234567901233 3087.8765432098767  792.9506  831.5926 1631.7037 2018   .1224115
                               5 700 15069  617 14452   72  844   61  929  16665.60606060606  6697.721212121212 15977.868685685284  8130.878787878788  8534.727272727272  2494.203  2589.506  3981.373 2018   .9041975
                               6 700   865    8   857    2   43    2   45 4882.1984126984125 1897.8174603174602  9507.031419551395 2412.9761904761904  2469.222222222222  854.1349  733.2222  1133.254 2018   .1771743
                              19 700  1351   14  1337    0   83    0   88  5863.163265306122  2332.598639455782 10048.499691949206 2881.9727891156463  2981.190476190476 1009.3062  916.9184  1297.374 2018   .2304217
                              27 700   525    6   519    0   31    0   38  4918.033333333334             2036.5 12990.762508797317 2409.2833333333333            2508.75     715.1     747.9 1230.2667 2018     .10675
                              29 700 50289 1171 49118  132 2915  112 3092  24534.14671814672  9816.181467181466  16426.38897442293 11743.710424710425 12790.436293436293  3756.297  3815.811  5515.645 2018  2.0497553
                              48 700   797   18   779    0   74    0   76  6040.925925925926 2540.4444444444443 12944.507206990487 2929.1975308641977 3111.7283950617284  796.5803  839.5185  1645.074 2018  .13193342
                               5 701 14020  556 13464   65  865   58  994  16217.10029498525 6517.0353982300885 15827.133560538923 7912.2684365781715   8304.83185840708 2426.8467  2519.283  3874.879 2018   .8645195
                               6 701   928    9   919    1   30    1   30           4589.875 1785.9338235294117  9353.565051884838 2269.8970588235293 2319.9779411764707   800.728  688.6912 1070.7206 2018  .20218416
                              19 701  1355   21  1334    2   79    2   82  5832.216216216216  2317.391891891892 10009.632110877736 2866.9054054054054  2965.310810810811   1005.75  912.3649 1289.1554 2018   .2323302
                              27 701   529    3   526    0   26    0   33  5734.137254901961  2371.549019607843  13180.79175464488  2805.627450980392 2928.5098039215686  835.2549  875.0588 1428.5686 2018   .0922545
                              29 701 55469 1560 53909  182 4471  144 4654 24634.422480620156  9854.813953488372 16432.322979194225 11791.267441860466  12843.15503875969  3772.205   3831.88  5538.771 2018  2.2516866
                              48 701   807   19   788    1   41    0   44   5419.32967032967   2280.78021978022 12869.239684048645 2629.8241758241757 2789.5054945054944  713.1868  751.7582  1479.099 2018   .1489114
                               5 702 15604  690 14914   82  692   47  898  16200.95588235294  6510.294117647059  15909.10105511216  7904.976470588235  8295.979411764705   2425.65  2517.029  3870.294 2018   .9631531
                               6 702  1123    5  1118    0   56    0   58 4433.2535211267605 1724.7535211267605  9290.833565366207 2192.6619718309857 2240.5915492957747  774.5493  663.7253      1034 2018  .25331283
                              19 702  1487   24  1463    3   66    2   77  5830.790540540541  2319.635135135135 10009.812361854458 2866.9864864864867  2963.804054054054 1002.9054  911.3041 1293.5067 2018  .25502545
                              27 702   598    3   595    0   18   -1   35  5227.160714285715 2159.9464285714284 13044.991219042244  2558.785714285714           2668.375  760.3214  795.1964 1306.5358 2018  .11440245
                              29 702 41710 1666 40044  217 3472  195 3755 24900.972549019607  9963.184313725491 16399.558431590605 11918.392156862745 12982.580392156862  3812.408  3873.106  5598.945 2018   1.675035
                              48 702   955   15   940    4   50    3   51  5356.652173913043            2255.75 12640.791874081595 2597.8152173913045  2758.836956521739  705.8152  740.3587 1464.9022 2018    .178283
                               5 703 10605  345 10260   34  631   20  746 16542.683734939757  6648.656626506024 15873.592083394527   8070.69578313253  8471.987951807228  2476.274  2569.946  3951.976 2018   .6410689
                               6 703   927    7   920    0   28    0   34  4594.462686567164  1784.858208955224  9378.004817972573 2271.5522388059703  2322.910447761194  803.4478  691.1716 1064.6791 2018   .2017646
                              19 703  1457   13  1444    0   94    0  100 5739.3708609271525 2285.3708609271525  9995.038375735761 2822.3576158940396 2917.0132450331125  988.4172  895.0662 1275.9602 2018  .25386056
                              27 703   504    3   501    0   28   -1   35  4461.805970149254 1849.6119402985075 12877.919045242645 2188.9402985074626  2272.865671641791  647.4627  674.0448 1124.4329 2018  .11295874
                              29 703 32305 1730 30575  137 2018  114 2222  25268.65338645418  10111.25498007968 16421.419702786403 12093.290836653387 13175.362549800797 3868.1475  3929.705  5682.104 2018  1.2784615
                              48 703   883   13   870    2   64    2   64  6118.848101265823  2575.025316455696 12911.504388791162 2963.4177215189875 3155.4303797468356  806.8354  849.7342 1667.6582 2018  .14430821
                               5 704  7922  343  7579   81  492   63  702 16938.956790123455  6807.049382716049  15950.26693640691  8263.225308641975  8675.731481481482   2536.12  2630.904  4048.028 2018   .4676793
                               6 704   691    6   685    1   42   -2   49           4830.384           1876.768    9434.6067346788           2387.184             2443.2    844.48    728.48  1117.712 2018  .14305282
                              19 704   906    9   897    5   52    4   62  6443.099236641221 2559.5648854961833 10166.699778344315 3162.7786259541986  3280.320610687023 1111.3359 1011.7405 1417.4275 2018  .14061555
                              27 704   344    4   340    0   15    0   27  5759.448979591837 2382.6326530612246 13259.241905579127 2813.6938775510203 2945.7551020408164  839.8163  879.8979  1429.306 2018  .05972794
                              29 704 18678  848 17830  248 1720  227 2009 25575.798387096773  10232.95564516129 16476.577708557765 12240.108870967742 13335.689516129032  3915.617  3977.863  5751.653 2018   .7302998
                              48 704   562   11   551    1   45    1   50  6513.438356164384 2744.8630136986303 13166.199548379322 3151.5342465753424  3361.904109589041   855.863  909.6849 1769.5616 2018  .08628315
                               5 705 10589  593  9996  120  733   84  862 16325.353115727003  6560.964391691395  15914.70090610372  7964.961424332344   8360.39169139466 2444.3176  2535.638  3901.024 2018    .648623
                               6 705   856   20   836    9   53    9   53  4664.087591240876  1816.043795620438  9422.150748349253  2307.058394160584  2357.029197080292   813.781  696.3431 1094.1825 2018     .18353
                              19 705  1274   19  1255    0  112   -1  118  5739.907284768212 2281.5099337748343  9947.858435898377 2822.0529801324506 2917.8543046357618  989.1259  896.8079  1271.437 2018   .2219548
                              27 705   456    6   450    0   36    0   45  4784.870967741936 1982.4516129032259 12979.695016186879  2344.951612903226 2439.9193548387098  694.9194  724.3065 1201.9839 2018  .09530038
                              29 705 24092 1371 22721  260 2528   48 2714 24443.203846153847  9779.996153846154 16382.506235438746 11700.384615384615 12742.819230769232 3742.0884  3801.077      5497 2018   .9856318
                              48 705   658   29   629    8   45    7   46          6107.4375           2568.225 12930.896531367545             2959.9          3147.5375   806.275   849.175 1663.8125 2018   .1077375
                               5 706 11713  356 11357   84  836   78  851  16568.91265060241  6657.993975903614 15945.860189138648  8083.512048192771  8485.400602409638  2480.434  2573.994 3959.3855 2018   .7069263
                               6 706   840   79   761   69   47   69   47  4352.062937062937 1694.1818181818182   9389.42444968187  2150.958041958042  2201.104895104895  760.4545  650.4685 1018.4406 2018   .1930119
                              19 706  1190   21  1169    2   71    2   72  5877.068027210885  2338.374149659864  9960.894555675277  2888.360544217687  2988.707482993197 1013.3605  919.2925  1301.204 2018   .2024819
                              27 706   479    7   472    0   37    0   37  4536.538461538462  1877.076923076923  12905.49243619401  2222.892307692308  2313.646153846154  660.1539   687.877 1136.6307 2018   .1055871
                              29 706 24785 1576 23209  381 2590  212 2642 24539.127413127415  9817.548262548262   16362.5307050777 11746.011583011583  12793.11583011583  3757.023  3816.919  5517.765 2018  1.0100197
                              48 706   734   29   705    4   57    4   58  5702.686046511628 2398.2906976744184 12815.065721142682 2764.8953488372094 2937.7906976744184  751.3372  791.7907 1555.1046 2018  .12871128
                               5 707 10646  389 10257  104  385   94  649 16504.891891891893  6633.318318318318 15940.840816623928  8052.375375375375  8452.516516516516 2470.5195 2563.5645  3944.027 2018   .6450209
                               6 707   898   23   875   13   31   13   44  4952.362903225807  1925.483870967742  9516.846348212153 2446.8225806451615 2505.5403225806454  864.4435  743.8951 1152.0887 2018   .1813276
                              19 707  1242   32  1210    4   68    4   90   5669.62987012987 2257.3896103896104  9961.990109645612 2787.4935064935066 2882.1363636363635  976.7922  882.8896 1261.4286 2018  .21906193
                              27 707   481   13   468    0   26    0   37 5188.8421052631575 2146.3508771929824  12955.86697079303 2541.5087719298244 2647.3333333333335  755.9298  788.3509 1299.9122 2018   .0926989
                              29 707 33405 2465 30940 1021 2732 1009 3107  25127.54761904762 10056.670634920634 16432.717980342593 12025.674603174602 13101.873015873016  3845.333  3906.627  5651.389 2018  1.3294175
                              48 707   786   23   763    4   40    4   53  5940.682926829269  2501.890243902439 12741.190395454578 2879.5365853658536 3061.1463414634145  781.3415  825.1464 1621.2317 2018  .13230802
                               5 708 10556  366 10190   85  606   71  688 16590.459214501512   6668.45921450151 15879.266500562275  8093.722054380664  8496.737160120845  2483.332 2576.3474 3965.3474 2019   .6362693
                               6 708   709   11   698    3   65    3   66  4742.221374045802  1845.824427480916  9467.092117642858 2344.5419847328244  2397.679389312977  827.6641   712.374 1105.0763 2019    .149508
                              19 708  1099   15  1084    2   85    2   89  5846.397260273972   2329.27397260274 10052.856702323363 2872.1643835616437 2974.2328767123286  1005.274  911.9932  1301.233 2019    .187979
                              27 708   416    7   409    3   30    3   39  5072.206896551724  2099.448275862069  12971.29088089469  2484.810344827586  2587.396551724138  737.8276  771.7931 1269.3966 2019  .08201558
                              29 708 34135 1525 32610  330 3565  321 3721 25574.072580645163 10233.229838709678  16512.58800804793 12239.862903225807 13334.209677419354 3914.9636   3977.77  5750.089 2019  1.3347503
                              48 708   677   28   649    7   56    7   58  5809.940476190476 2443.0476190476193 12797.293501189843 2816.6190476190477 2993.3214285714284  765.7619  804.4643 1589.2738 2019  .11652443
                               5 709 10891  498 10393  170  681  164  746 16621.187311178248  6679.815709969788 15985.543514358746   8109.73413897281  8511.453172205438  2488.737  2582.402  3970.529 2019    .655248
                               6 709   806    8   798    3   36    3   37  4572.328467153285 1780.2481751824816  9393.482892091717 2261.4671532846714 2310.8613138686133  798.1971  683.9489  1068.781 2019   .1762778
                              19 709  1063   17  1046    5   61    5   65  6072.288732394366 2414.8028169014083 10056.761205785468 2984.7323943661972  3087.556338028169 1048.3802     950.5 1341.3873 2019  .17505755
                              27 709   416    8   408    4   32    4   35  5395.574074074074 2228.6296296296296   13020.7834271943 2639.8333333333335  2755.740740740741  786.7778  823.1296  1345.537 2019  .07710023
                              29 709 38696 1619 37077  421 3508  411 3628           25364.94          10149.888 16448.710606206376          12139.228          13225.712  3882.988  3944.348    5703.5 2019  1.5255704
                              48 709   709   12   697    1   47    1   47  5398.516483516483  2271.032967032967 12744.513396023352 2617.6373626373625  2780.879120879121  711.7363  748.4945 1474.6483 2019  .13133238
                               5 710 13402  634 12768  297  846  278  949 16745.771341463416  6729.737804878048  15941.71582832849  8169.265243902439  8576.506097560976 2506.0305  2601.756 4001.1646 2019   .8003215
                               6 710   820   10   810    0   56    0   56  5459.954545454545 2121.5363636363636   9635.52043778995             2697.1 2762.8545454545456  951.6818  823.9909  1263.391 2019   .1501844
                              19 710  1255   28  1227    6  106    6  110  6057.347517730496 2408.0851063829787 10099.180646078858 2976.6028368794327  3080.744680851064 1044.1489  948.2341 1339.3263 2019   .2071864
                              27 710   446    5   441    4   40    4   45  5321.854545454546 2200.8545454545456 13135.008292688111             2604.6 2717.2545454545457     774.6  812.5273 1325.9818 2019  .08380537
                              29 710 47765 2102 45663  654 3605  610 3788  24906.95294117647  9966.184313725491 16347.449789523687 11921.725490196079 12985.227450980392  3812.882  3873.529  5600.824 2019  1.9177376
                              48 710   777   28   749    8   75    6   75  6107.113924050633 2569.0506329113923 13122.339471625522 2957.6075949367087  3149.506329113924  805.5443  850.6456  1661.228 2019  .12722868
                               5 711 11415  450 10965  118  829   96  931 16703.313069908814  6712.352583586626 15956.179781879899  8148.930091185411  8554.382978723404  2500.982  2595.067  3989.799 2019   .6833974
                               6 711   693   11   682    0   62    0   63               4907           1908.096  9500.345305310288            2425.08            2481.92   856.552    737.24  1141.288 2019  .14122681
                              19 711  1009   28   981    1   78    1   82  6315.171641791045  2512.276119402985 10146.333084904101  3102.007462686567 3213.1641791044776  1088.097   991.194  1391.224 2019  .15977396
                              27 711   356   11   345    1   25    1   30  5223.696428571428  2160.339285714286 13102.013830109117           2558.125 2665.5714285714284  760.3929  796.5893  1302.625 2019 .068150975
                              29 711 52053 1883 50170  329 3781  311 3936 25561.104838709678 10230.677419354839  16385.51055513777 12233.504032258064 13327.600806451614  3911.968  3972.843  5750.383 2019  2.0364144
                              48 711   682   19   663    3   57    3   59  5601.724137931034  2359.310344827586 12559.103142395177 2715.6206896551726  2886.103448275862  737.5632  776.3793 1530.6093 2019  .12174823
                              end
                              format %tm moyr_matricula
                              label values idprovdis idprovdis
                              label def idprovdis 5 "B", modify
                              label def idprovdis 6 "BA", modify
                              label def idprovdis 19 "GR", modify
                              label def idprovdis 27 "LO", modify
                              label def idprovdis 29 "M", modify
                              label def idprovdis 48 "VA", modify
                              Edit #15:

                              Thank you for your advices, help (and time!) on the code

                              Comment

                              Working...
                              X