Announcement

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

  • Issue with reghdfe within a program

    Dear all,

    I am having trouble with some debugging. I created a program to run some regressions using reghdfe and ivreghdfe, please see below a simplified version of it.


    Code:
      capture program drop reg_prog
      program reg_prog
      syntax varlist( max=1) [if] [, absorb(varlist) filename(string) controls(namelist) het_var(namelist) ]
      preserve
      if `"`if'"' != "" {
      keep `if'
      }
        di `interaction'
      global outcome `1'
      global fixed_effects `absorb'
      global controls_reg `controls'
        eststo clear
      estimates clear
        qui reghdfe $outcome c.treatment##c.`het_var', a($fixed_effects) vce(cl facility_cod)
      qui sum `e(depvar)' if e(sample)
      qui estadd scalar control_mean= r(mean)
      qui estadd scalar control_std= r(sd)
      add_scalars_hiv
      qui estimates store model1, title("OLS")
        restore
      end
     
    I then run the following loop to execute the regressions:
    Code:
      local names " "name1" "name2" "name3" "name4" "
      local i = 1
      foreach var in var1 var2 cvar dvar {
      global outcome `var'
      local q: word `i' of `names'
      dis `i' " - " "`q'"
      
      reg_prog $outcome, controls($controls) absorb(abs1 abs2) filename("tables/tab_`q'_interaction.tex") het_var(hetvar)
        local ++i
      }
     
    However, I get the following error:
    invalid 'absorb'.

    What am I not seeing?
    Thanks in advance


  • #2
    global fixed_effects "`absorb'"

    Comment


    • #3
      Thanks George for your answer! However, I still get an error. I also tried adding the variables I want to absorb directly into the reghdfe command inside the program instead of using the global fixed_effect, but I still get the same error.
      I find it weird because when I run the reghdfe command outside of the program I do not get any error.

      Comment


      • #4
        Code:
        sysuse auto, clear
        
        capture program drop reg_prog
        program reg_prog
        syntax varlist (max=1) [if] [, absorb(namelist) filename(string) controls(namelist) het_var(varlist) ]
        tokenize `varlist'
        local outcome = "`1'"
        di "`outcome'" 
        di "`absorb'"
        di "`controls'"
        reghdfe `outcome' `controls' , absorb(`absorb') cluster(`absorb')
        end
         
        reg_prog price, controls(mpg weight) absorb(rep78 foreign) het_var(foreign)

        Comment


        • #5
          Thank you! The "tokenize `varlist' " command was the key

          Comment

          Working...
          X