Announcement

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

  • did_multiplegt option average_effect() incorrectly specified

    Hello Stata Forum,

    I am running a staggered TWFE with dynamic/heterogenous effects and a continuous treatment. My code is as follows:

    Code:
     did_multiplegt ch4hh county_fips year cs_treatshare, controls(AvgHHSize Population demshare MedianIncome RenterFraction facnum) breps(10) cluster(county_fips)placebo(5) dynamic(5) robust_dynamic average_effect
    This gets me an average effect, but it is the incorrect one. The average effect I would like is weighed. I try to weigh it accordingly by specifying
    Code:
    average_effect("prop_number_switchers")
    :

    Code:
     did_multiplegt ch4hh county_fips year cs_treatshare, controls(AvgHHSize Population demshare MedianIncome RenterFraction facnum) breps(10) cluster(county_fips)placebo(5) dynamic(5) robust_dynamic average_effect("prop_number_switchers")
    However, I get an error that says
    Code:
    option average_effect() incorrectly specified
    .

    I couldn't figure out why this was, so I looked into the source code of average_effect in did_multiplegt. I still couldn't find anything. Below is the source code:

    Code:
    /////// Computing average effect, if option requested
    
    if "`average_effect'"!=""{
    scalar average_effect_int=0
    scalar var_average_effect_int=0
    scalar N_average_effect_int=0
    *NEWW
    scalar N_switch_average_effect_int=0
    *END NEWW
    
    //// Computing weights
    
    *NEWW
    
    /*
    // Weights for simple average
    
    if "`average_effect'"=="simple"{
    scalar check_cov=1
    matrix Weight=J(`dynamic'+1,1,1/(`dynamic'+1))
    }
    
    // Weights proportionnal to number of switchers for which each effect is estimated
    
    if "`average_effect'"=="prop_number_switchers"{
    scalar check_cov=1
    scalar total_switchers=0
    forvalue i=0/`=`dynamic''{
    matrix Weight[`i'+1,1]=N_switchers_effect_`i'_2
    scalar total_switchers=total_switchers+N_switchers_effect_`i'_2
    }
    matrix Weight=Weight*(1/total_switchers)

    Any help would be greatly appreciated. I'm not sure why I am incorrectly specifying average_effect.

    Best,
    David W.






  • #2
    From the output of help did_multiplegt we see
    Code:
    Syntax
    
        did_multiplegt Y G T D [if] [in] [, robust_dynamic dynamic(#) average_effect placebo(#) longdiff_placebo jointtestplacebo
            controls(varlist) trends_nonparam(varlist) trends_lin(varlist) count_switchers_contr recat_treatment(varlist)
            threshold_stable_treatment(#) weight(varlist) switchers(string) if_first_diff(string) count_switchers_tot discount(#)
            breps(#) cluster(varname) covariances seed(#) graphoptions(string) save_results(path)]
    The average_effect option does not seem to take arguments. Looking at the syntax command at the top of the source for did_multiplegt tells us (in part)
    Code:
        syntax varlist(min=4 numeric) [if] [in]  [, RECAt_treatment(varlist numeric) ... covariances AVerage_effect ...]
    which confirms that an argument would generate the error you saw.

    However, looking at older commented-out code suggests that in the past it did take an argument, and the detailed code you show in post #1 is in fact commented out by the /* just below *NEWW near the top of the code.

    In the more complete code fragment below I have colored in grey the lines that are commented out and in green the lines added. Perhaps looking at these you can figure out if what you want remains possible.

    Code:
    if "`average_effect'"!=""{
    
    scalar average_effect_int=0
    scalar var_average_effect_int=0
    scalar N_average_effect_int=0
    *NEWW
    scalar N_switch_average_effect_int=0
    *END NEWW
    
    
    //// Computing weights
    
    *NEWW
    
    /*
    // Weights for simple average
    
    if "`average_effect'"=="simple"{
    scalar check_cov=1
    matrix Weight=J(`dynamic'+1,1,1/(`dynamic'+1))
    }
    
    // Weights proportionnal to number of switchers for which each effect is estimated
    
    if "`average_effect'"=="prop_number_switchers"{
    scalar check_cov=1
    scalar total_switchers=0
    forvalue i=0/`=`dynamic''{
    matrix Weight[`i'+1,1]=N_switchers_effect_`i'_2
    scalar total_switchers=total_switchers+N_switchers_effect_`i'_2
    }
    matrix Weight=Weight*(1/total_switchers)
    
    }
    */
    
    scalar total_weight=0
    matrix Weight=J(`dynamic'+1,1,0)
    forvalue i=0/`=`dynamic''{
    matrix Weight[`i'+1,1]=denom_DID_ell_`i'
    scalar total_weight=total_weight+denom_delta_`i'
    }
    matrix Weight=Weight*(1/total_weight)
    
    *END NEWW
    
    //// Computing average effect, its variance, and returning results 
    
    forvalue i=0/`=`dynamic''{
    scalar average_effect_int=average_effect_int+Weight[`i'+1,1]*effect_`i'_2
    scalar N_average_effect_int=N_average_effect_int+N_effect_`i'_2
    scalar N_switch_average_effect_int=N_switch_average_effect_int+N_switchers_effect_`i'_2
    *NEWW
    if "`breps'"!="0"&"`covariances'"!=""{
    *END NEWW
    scalar var_average_effect_int=var_average_effect_int+Weight[`i'+1,1]^2*se_effect_`i'_2^2
    if `i'<`dynamic'{
    forvalue j=`=`i'+1'/`=`dynamic''{
    scalar var_average_effect_int=var_average_effect_int+Weight[`i'+1,1]*Weight[`j'+1,1]*2*cov_effects_`i'_`j'_int
    }
    }
    *NEWW
    }
    *END NEWW
    }

    Comment


    • #3
      Hello

      I am running a staggered TWFE with heterogenous effects and a continuous treatment. My code is as follows:
      did_multiplegt y_O_E Region_T_P_S survey_year ANEM, robust_dynamic dynamic(5) placebo(5) breps(50) controls(education)
      I get this error message :
      The command was not able to estimate the treatment effect at the period when groups' treatment change.
      If your treatment is continuous or takes a large number of values, you may need to use
      the threshold_stable_treatment option to ensure you have groups whose treatment does not change
      over time. You may also need to use the recat_treatment option to discretize your treatment variable.
      Could you please help me on this

      Comment

      Working...
      X