Announcement

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

  • Feature or bug? fvexpand ignores level of categorical variable in time lag of an interaction term

    I am curious about the following behavior of fvexpand (and other commands):

    I want to take a time lag of an interaction term which includes a specific level of a categorical variable. When I do that in the following way, the level of the categorical variable is ignored:
    [CODE]
    . webuse psidextract

    . fvexpand L.(4.ed#c.wks)

    . display "`r(varlist)'"
    4bL.ed#cL.wks 5L.ed#cL.wks 6L.ed#cL.wks 7L.ed#cL.wks 8L.ed#cL.wks 9L.ed#cL.wks 10L.ed#cL.wks 11L.ed#cL.wks 12L.ed#cL.wks 13L.ed#cL.wks 14L.ed#cL.wks 15L.ed#cL.wks 16L.ed#cL.wks 17L.ed#cL.wks
    [CODE]
    Is this intended?

    I know that I can do the following to get around this:
    Code:
    . fvexpand 4L.ed#cL.wks
    
    . display "`r(varlist)'"
    4L.ed#cL.wks
    But that is not my point. I am trying to understand the above behavior because it affects how I should deal in my code with time lags of an arbitrary variable, say L.`var', where `var' may or may not be an interaction term as above.
    https://twitter.com/Kripfganz

  • #2
    It appears that the only way to choose a specific level of the factor variable is to use the -if- qualifier. It may be a bug, I do not know.

    Code:
    webuse psidextract
    fvexpand L.(i.ed#c.wks) if 4.ed
    Res.:

    Code:
    . return list
    
    macros:
                  r(tsops) : "true"
                  r(fvops) : "true"
                r(varlist) : "4L.ed#cL.wks"

    Comment


    • #3
      I just noticed that the problem does not occur in Stata 13 and 14, while it does occur in Stata 15 and 16. A similar issue arises with fvunab. In Stata 13 or 14, I correctly get
      Code:
      . fvunab varlist : L.(4.ed#c.wks)
      
      . di "`varlist'"
      i4L.ed#cL.wks
      In Stata 15 and 16, the level is missing:
      Code:
      . fvunab varlist : L.(4.ed#c.wks)
      
      . di "`varlist'"
      iL.ed#cL.wks
      My guess is that this is an unintended side effect of a change introduced in Stata 15, see help whatsnew14to15:
      7. Factor variables now work more like you would expect they would

      Consider fitting a model with the terms

      . est_command ... i.a i(2 3).a#i.b ...

      What should happen? What happens now should be more in line with your expectations. i.a adds main-effect coefficients for each level of a, and the interaction i(2 3).a#i.b is restricted to a's levels 2 and 3.

      What used to happen was rather more surprising. The entire RHS of the model was restricted to levels 2 and 3 of a.
      https://twitter.com/Kripfganz

      Comment


      • #4
        Sebastian Kripfganz has found a bug. Thanks to the simple example and Sebatian's above guess, we have been able to determine the source of the bug and should have this fixed in a Stata 16 update soon.

        Comment

        Working...
        X