Announcement

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

  • permute with reghdfe

    Dear All,
    Please, I am using reghdfe absorbing a(counties years). I want to 'scramble' years, assigning the 'wrong' years for each observation and then run 500 repetitions to calculate the p-value of those repetitions. Then, in another exercise, I want to 'scramble' the counties. I am trying to use permute, but as counties and years are not included as independent variables, it does not work. Does anyone know how I could do this exercise?
    Many thanks.

  • #2
    I think you could use the user-written package shufflevar (ssc install shufflevar, replace) and then write a wrapper which combines shuffling the target vars and feeding them into reghdfe. Using simulate you can accumulate your results.
    Best wishes

    Stata 18.0 MP | ORCID | Google Scholar

    Comment


    • #3
      Hi Felix, thank you for answering.
      I am not sure how I code 'write a wrapper which combines shuffling the target vars and feeding them into reghdfe'. Do you have an idea?
      Thank you.

      Comment


      • #4
        Well its not too complicated but I am not familiar with reghdfe and what kind of statistic you are interested in. So here is a generic example using regress. Say, you are interested in the beta coefficient of weight and you are shuffling whether cars are foreign built or not.

        Code:
        
        clear all
        sysuse auto
        
        
        *Write wrapper*
        cap program drop shuffler
        program define shuffler, rclass
            shufflevar foreign
            reg mpg weight foreign_shuffled
            return scalar beta_weight = _b[weight]
            drop foreign_shuffled
        end
        
        
        *Test program*
        shuffler
        return list
        
        
        *Run simulation*
        simulate beta=r(beta_weight), reps(100) seed(123) nodots: shuffler
        sum beta, det
        hist beta
        Best wishes

        Stata 18.0 MP | ORCID | Google Scholar

        Comment


        • #5
          That's great help! Thank you very much Felix!!

          Comment

          Working...
          X