Announcement

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

  • fvset base with negative period generates error

    Hi, I am trying to conduct pre trend test for Diff-in-diff model by the following code:

    Code:
    gen relative_year = year - 2014 (treatment year)
    * Setting period -1 as the base year
    Code:
    fvset base -1 relative_year
    
    reghdfe y i.treat_dummy##i.relative_year, absorb(uniqueid year) vce(cluster uniqueid)
    
    test _b[1.treat_dummy#-4.relative_year] = _b[1.treat_dummy#-3.relative_year] = _b[1.treat_dummy#-2.relative_year] = 0
    However, fvset base -1 relative_year keeps generating the error "invalid base specification". I tried with zero or positive number like fvset base 0 relative_year and it works but not with the negative values, which is supposed to be the correct one.

    Any help would be appreciated!

    Thanks

  • #2
    since the help file says, "nonnegative integer value", it is unclear why you expected this to work; maybe a clearer explanation of what you want to do might engender more positive replies

    Comment


    • #3
      Just to add, this is nothing specific to the fvset command as such. Factor variables in Stata cannot take on negative values.

      Here is the relevant extract from help fvvarlist
      Categorical variables to which factor-variable operators are applied must contain nonnegative integers with values in the range 0 to 32,740, inclusive.
      So, even if you had not used the fvset command at all, your reghdfe command would have thrown an error. Consider:
      Code:
      . clear
      . set obs 5
      Number of observations (_N) was 0, now 5.
      
      . gen x = runiformint(-10,-5)
      . gen y = runiformint(5, 10)
      . regress y i.x
      x:  factor variables may not contain negative values
      r(452);
      However, this is not a constraint for your analysis. For instance, you can create another integer variable whose labels correspond to the original, and run the analysis on that:
      Code:
      . egen x2 = group(x), label
      . label li x2
      x2:
                 1 -10
                 2 -9
                 3 -8
      
      . sum x2
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
                x2 |          5         2.4    .8944272          1          3
      
      . regress y i.x2
      
            Source |       SS           df       MS      Number of obs   =         5
      -------------+----------------------------------   F(2, 2)         =      0.60
             Model |         4.8         2         2.4   Prob > F        =    0.6250
          Residual |           8         2           4   R-squared       =    0.3750
      -------------+----------------------------------   Adj R-squared   =   -0.2500
             Total |        12.8         4         3.2   Root MSE        =         2
      
      ------------------------------------------------------------------------------
                 y | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
                x2 |
               -9  |          3   2.828427     1.06   0.400     -9.16974    15.16974
               -8  |          1   2.309401     0.43   0.707    -8.936551    10.93655
                   |
             _cons |          6          2     3.00   0.095    -2.605305    14.60531
      ------------------------------------------------------------------------------
      Last edited by Hemanshu Kumar; 30 Jul 2025, 23:16.

      Comment


      • #4
        Thank you Rich Goldstein and Hemanshu Kumar !!

        Comment

        Working...
        X