Announcement

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

  • Synth Control Unit Error

    Hi I am facing this error when running synth. If someone can tell me what I can do to resolve it, that would be great. Thank you.
    tsset C1 Year
    panel variable: C1 (strongly balanced)
    time variable: Year, 1990 to 2019
    delta: 1 unit
    . synth Educationalattainmentatleast Quotas GDPcurrentUS GDPgrowthannual GDPpercapitaCurrentUS Governmentexpenditureoneducat Governmente
    > xpenditureonhealth DemocracyPerformanceNumber Populationages1564oftota Populationages1564female Populationages1564male Populationages1
    > 564total Populationfemale Populationfemaleoftotal Populationmale Populationtotal Educationalattainmentatleast(1990) Educationalattainm
    > entatleast(1991) Educationalattainmentatleast(1992) Educationalattainmentatleast(1993) Educationalattainmentatleast(1994) Educationala
    > ttainmentatleast(1995) Educationalattainmentatleast(1996) Educationalattainmentatleast(1997) Educationalattainmentatleast(1998) Educat
    > ionalattainmentatleast(1999) Educationalattainmentatleast(2000) Educationalattainmentatleast(2001) Educationalattainmentatleast(2002),
    > trunit(17)trperiod(2003)xperiod(1990(1)2002) nested fig
    Synthetic Control Method for Comparative Case Studies
    First Step: Data Setup
    control units: for 1 of out 20 units missing obs for predictor GDPcurrentUS in period 1990 -ignored for averaging
    control units: for 1 of out 20 units missing obs for predictor GDPpercapitaCurrentUS in period 1990 -ignored for averaging
    control units: for 14 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 1990 -ignored for averaging
    control units: for 15 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 1991 -ignored for averaging
    control units: for 15 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 1992 -ignored for averaging
    control units: for 16 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 1993 -ignored for averaging
    control units: for 16 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 1994 -ignored for averaging
    control units: for 15 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 1995 -ignored for averaging
    control units: for 15 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 1996 -ignored for averaging
    control units: for 17 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 1997 -ignored for averaging
    control units: for 11 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 1998 -ignored for averaging
    control units: for 6 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 1999 -ignored for averaging
    control units: for 8 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 2000 -ignored for averaging
    control units: for 8 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 2001 -ignored for averaging
    control units: for 10 of out 20 units missing obs for predictor Governmentexpenditureoneducat in period 2002 -ignored for averaging
    control units: for at least one unit predictor Governmentexpenditureoneducat is missing for ALL periods specified
    r(198);
    Last edited by Prachi Mehta; 25 May 2022, 08:24. Reason: synth

  • #2
    I don't understand the problem.



    Classic SCM works by calculating summary statistics for the time periods in question. Thus, if the variable you've specified has no observations for the time period you've specified, then of course the estimator can't use that donor since it has no information to work with.

    Code:
    u "http://econ.korea.ac.kr/~chirokhan/panelbook/data/basque-clean.dta", clear
    
    loc int_time = 1975
    
    g treated = cond(regionno==17 & year >= `int_time',1,0)
    
    labvars year gdpcap "Year" "ln(GDP per 100,000)"
    
    replace regionname = trim(regexr(regionname,"\(.+\) *",""))
    
    egen id = group(regionname), label(regionname) // makes a unique ID
    
    order id, b(year)
    
    *keep if year >= 1960
    drop if inlist(id,18) //12
    
    as id != 18
    
    drop regionno
    xtset id year, y
    
    replace gdp = . if id == 14
    
    cls
    
    
    loc x 1961(1)1969
    
    loc y 1960(1)1969
    
    loc z 1964(1)1969
    
     cap 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 fig
    
    tempvar missinggdp
        
    bys id: g `missinggdp' = _N if gdp ==.    
    
    levelsof id if !mi(`missinggdp'), l(dropids)
        
    drop if id ==`dropids'
    
    as id != 14
    
    
    set tr off
     synth 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(4) ///
        trperiod(`int_time') ///
        allopt nested fig
    The first example fails because I've artificially decided that all of Navarre's values will be missing. When I drop Navarre from the analysis, the SCM can now work since all of the donor pool has at least 1 non-missing observation in the pre-intervention period.



    EDIT: Suppose we have multiple units that have all missing values. One approach to solving this would be
    Code:
    u "http://econ.korea.ac.kr/~chirokhan/panelbook/data/basque-clean.dta", clear
    
    loc int_time = 1975
    
    g treated = cond(regionno==17 & year >= `int_time',1,0)
    
    labvars year gdpcap "Year" "ln(GDP per 100,000)"
    
    replace regionname = trim(regexr(regionname,"\(.+\) *",""))
    
    egen id = group(regionname), label(regionname) // makes a unique ID
    
    order id, b(year)
    
    *keep if year >= 1960
    drop if inlist(id,18) //12
    
    as id != 18
    
    drop regionno
    xtset id year, y
    
    replace gdp = . if id == 14 | id ==1
    
    cls
    
    
    loc x 1961(1)1969
    
    loc y 1960(1)1969
    
    loc z 1964(1)1969
    
     cap 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 fig
    
    tempvar missinggdp
        
    bys id: g `missinggdp' = _N if gdp ==.    
    
    levelsof id if !mi(`missinggdp'), l(dropids) sep(",")
        
    drop if inlist(id,`dropids')
    
    set tr off
     synth 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(4) ///
        trperiod(`int_time') ///
        allopt nested fig
    where we use levelsof to get all these in a list for the inlist function and then delete them that way.


    EDIT 2: I would also recommend you use the allsynth command by Justin Wiltshire. His command, sort of like my own, is this super-charged version of the classic synth and allows for better functionality with additional tests you can do.
    Last edited by Jared Greathouse; 25 May 2022, 09:01.

    Comment

    Working...
    X