Announcement

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

  • Can't use synth because main variable does not exist as a numeric

    Hey,

    I'm working with a panel dataset and try to apply synthetic controls by using the synth command but I get the following message:


    . synth Fish_val_EX_CHN(2005) Fish_val_EX_CHN(2003) Fish_val_EX_CHN(2000), trunit(70
    > 31) trperiod(2011) xperiod(2000(1)2010) nested fig
    ------------------------------------------------------------------------------------
    Synthetic Control Method for Comparative Case Studies
    ------------------------------------------------------------------------------------

    First Step: Data Setup
    ------------------------------------------------------------------------------------
    Fish_val_EX_CHN(2005) does not exist as a (numeric) variable in dataset
    r(198);

    I don't know why this suddenly happens. I used synth with the same dataset earlier today and had no problems. I wanted to divide Fish_val_EX_CHN/1000000 and after that this issue occured.



    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int Year str23 country long Fish_val_EX_CHN double(Temp_C Dist_CHN Tot_Fish_prod Real_FX Abs_Lat Coast_L Cap_Lab_R Trop_Land_share RD_share_GDP Aqua_prod_ton Aqua_prod_share_tot) float Country_ID
    2000 "Rep. of Korea"  81124815 11.5 809.5382 2506252  83.43557027765927 35.90776 2413  181711.6610506022 0 2.1  667883   .0377497408054814 809
    2001 "Rep. of Korea"  52142790 11.5 809.5382 2677494  78.20622978694682 35.90776 2413  186785.4798102272 0 2.3  668022   .0405036684708866 809
    2002 "Rep. of Korea"  45785097 11.5 809.5382 2499127  82.45252467948828 35.90776 2413 190680.96708887594 0 2.2  794340  .03914863064816302 809
    2003 "Rep. of Korea"  65285364 11.5 809.5382 2502112  83.34565406586015 35.90776 2413  211950.9113828802 0 2.3  839845 .036372445144756266 809
    2004 "Rep. of Korea" 116946151 11.5 809.5382 2542856   84.4091683696239 35.90776 2413 233018.65934260548 0 2.4  952856 .029224078896289415 809
    2005 "Rep. of Korea"  96604343 11.5 809.5382 2720037  94.16744681025544 35.90776 2413 261676.33958147527 0 2.5 1057725 .029396528259476164 809
    2006 "Rep. of Korea"  60097042 11.5 809.5382 3052166 100.65588235665079 35.90776 2413   280624.133415942 0 2.7 1279163  .03320545824710178 809
    2007 "Rep. of Korea" 142358089 11.5 809.5382 3288047                100 35.90776 2413  299359.6854835015 0 2.9 1399075  .02808037894880329 809
    2008 "Rep. of Korea" 168567163 11.5 809.5382 3366428  80.67631176170084 35.90776 2413  320515.3043235146 0   3 1394818  .03171248269228281 809
    2009 "Rep. of Korea" 120786302 11.5 809.5382 3204179  72.21748011761848 35.90776 2413 320435.20921299624 0 3.1 1331719 .032677637084487045 809
    2010 "Rep. of Korea" 195157503 11.5 809.5382 3112810  78.77197196815182 35.90776 2413  316093.1472635671 0 3.3 1377233 .035485864039701324 809
    2011 "Rep. of Korea" 414000247 11.5 809.5382 3257098  79.38658201522226 35.90776 2413 309393.06106546015 0 3.6 1499335  .04067642030778735 809
    2012 "Rep. of Korea" 306477170 11.5 809.5382 3189134  79.50851806964307 35.90776 2413  325611.2650322277 0 3.9 1509226  .04935428722857725 809
    2013 "Rep. of Korea" 289746739 11.5 809.5382 3138722  84.30108308759111 35.90776 2413 340266.54666936205 0   4 1533446  .04872208230167471 809
    2014 "Rep. of Korea" 224528615 11.5 809.5382 3323489   89.3367988520243 35.90776 2413  355209.5054660225 0 4.1 1567442  .05814754549804132 809
    2015 "Rep. of Korea" 199406412 11.5 809.5382 3335467   90.6098587725274 35.90776 2413 369631.87863532023 0   4 1676485 .047895127236957886 809
    2016 "Rep. of Korea" 252050381 11.5 809.5382 3231019  88.37155179539953 35.90776 2413 378462.11799395905 0   4 1859220  .04985040660676139 809
    2017 "Rep. of Korea" 232774411 11.5 809.5382 3697861  91.05733070221126 35.90776 2413  397119.8755508933 0 4.3 2334719  .06410671794354042 809
    2018 "Rep. of Korea" 247043337 11.5 809.5382 3624756  92.18888074545826 35.90776 2413 408718.07266367954 0 4.5 2278850  .07360513203878491 809
    2019 "Rep. of Korea" 321707431 11.5 809.5382       .  87.53400648009686 35.90776 2413  416608.8651022231 0   . 2406351                   . 809
    end
    format %ty Year

    Year int %ty Year
    country str23 %23s Country
    Fish_val_EX_CHN long %14.2f Fish, crustaceans, molluscs, aquatic
    invertebrates nes


    I hope someone can help me. Thank you in advance!

    Rolf

  • #2
    Your problem here is that you're including your outcome as a lag. The correct way this should look is a little like this
    Code:
    loc x 1961(1)1969
    
    loc y 1960(1)1969
    
    loc z 1964(1)1969
    
    
    
    tempfile scmbasque
    
    cap qui allsynth gdpcap /// classic SCM- Justin Wiltshire's command
        gdpcap(`y') ///
        pop(1969) ///
            sec_agriculture(`x') ///
            sec_energy(`x') ///
            sec_industry(`x') ///
            sec_construction(`x') ///
            sec_svc_venta(`x') ///
            sec_svc_nonventa(`x') ///
        school_illit(`z') ///
        school_prim(`z') ///
        school_med(`z') ///
        school_high(`z') ///
        invest(`z'), ///
        trunit(15) ///
        trperiod(`int_time') ///
        allopt nested keep(scmbasque, replace)
    See how the outcome is gdpcap? I begin with this variable, and then I include its lags. You begin with Fish_val_EX_CHN(2005), and thus you didn't feed an outcome variable to synth. And, from a literal standpoint, "Fish_val_EX_CHN(2005)" is not a variable in your data, Fish_val_EX_CHN is.



    EDIT: by the way, unless you have data before 2000, you don't need to have xperiod(2000(1)2010) as an option here. synth averages over the whole pretreatment period automatically.

    EDIT 2: The FAQ asks that you specify that synth is user written, also. I know where it comes from and what it is because I've written two SCM commands, but presumably not everyone knows what it is, so in the future, state that you're working with a user written command.
    Last edited by Jared Greathouse; 22 Apr 2022, 15:38.

    Comment


    • #3
      Thanks a lot, I also just realised which mistake I made. Thank you!

      Comment

      Working...
      X