Announcement

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

  • Incorrect Stata Error Message for xtdidregress

    When I estimate
    Code:
    import delim "https://raw.githubusercontent.com/SucreRouge/synth_control/master/basque.csv", clear
    
    egen id = group(regionname)
    
    drop if inlist(id,18)
    
    g weight = 0
    
    replace weight = 0.5327967 if id ==9 // catalan
    
    replace weight = 0.0225190 if id ==13 // madrid
    
    replace weight =  0.1151287 if id == 16 // asturias 
    
    replace weight = 0.2892709 if id ==17 //la rioja
    
    replace weight = . if weight ==0
    
    
    drop v1
    
    xtset id year, y
    
    g treat = cond(id==4 & year >=1975,1,0)
    
    cls
    
    xtdidregress (gdpcap) (treat) [aw=weight], group(id) time(year)
    Stata tells me
    invalid treatment variable
    Either the treatment does not vary or it is never zero. The treatment variable is either zero for
    controlled observations or 1 for treated observations. To use a continuous treatment, specify (treat,
    continuous) for your treatment specification.
    even though this is preposterous, it's 0 for all states before 1975, 1 for the Basque Country after 1975, and 0 for all other states after 1975. However, when I estimate
    Code:
    import delim "https://raw.githubusercontent.com/SucreRouge/synth_control/master/basque.csv", clear
    
    egen id = group(regionname)
    
    drop if inlist(id,18)
    
    g weight = 0
    
    replace weight = 0.5327967 if id ==9 // catalan
    
    replace weight = 0.0225190 if id ==13 // madrid
    
    replace weight =  0.1151287 if id == 16 // asturias 
    
    replace weight = 0.2892709 if id ==17 //la rioja
    
    replace weight = . if weight ==0
    
    
    drop v1
    
    xtset id year, y
    
    g treat = cond(id==4 & year >=1975,1,0)
    
    cls
    
    xtdidregress (gdpcap) (treat), group(id) time(year)
    the error goes away and the DD estimates as we'd want it to. Why? The weights have nothing to do with the treatment variable, so it's unclear to me why use of analytic weights would affect it in one instance, but not the other.

  • #2
    Hi Jared
    It seems to me that in your first example, county "id==4" (the treated country) is getting a weight of zero.
    Now, when a variable has weight of zero, stata assumes its out of the sample. So appears there isn't a treated unit. Thus explaining the error you report.
    HTH

    Comment


    • #3
      Yes, but, I replace all weights as missing if they originally had the 0 value before running the analysis. Presumably this includes The Basque Country, no? FernandoRios

      Comment


      • #4
        Code:
        . g treat = cond(id==4 & year >=1975,1,0)
        
        . 
        . tab id treat if weight!=.
        
        group(regi |   treat
           onname) |         0 |     Total
        -----------+-----------+----------
                 9 |        43 |        43 
                13 |        43 |        43 
                16 |        43 |        43 
                17 |        43 |        43 
        -----------+-----------+----------
             Total |       172 |       172

        Comment


        • #5
          I should listen to people like this more often, who advise that the treatment unit should have a weight of one. Problem solved, thank you all.

          Comment

          Working...
          X