Announcement

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

  • Sequential factor variables create "extra" variables. How?

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . fvexpand 1.foreign#0.rep78#c.price
    
    . return list
    
    macros:
                  r(fvops) : "true"
                r(varlist) : "1o.foreign#0o.rep78#co.price"
    
    . fvexpand  1.foreign#1.rep78
    
    . return list
    
    macros:
                  r(fvops) : "true"
                r(varlist) : "1o.foreign#1o.rep78"
    So far, so good. But then if I expand both together…

    Code:
    . fvexpand 1.foreign#0.rep78#c.price 1.foreign#1.rep78
    
    . return list
    
    macros:
                  r(fvops) : "true"
                r(varlist) : "1o.foreign#0b.rep78#co.price 1o.foreign#1o.rep78#co.price 1o.foreign#0b.rep78 1o.foreign#1o.rep78"
    By what logic did 1o.foreign#1o.rep78#co.price 1o.foreign#0b.rep78 get created?

  • #2
    You didn't get a quick answer. Most of us don't use fvexpand since most estimators allow factor variables and using factor variables lets you use the power of margins after the estimation.

    Comment


    • #3
      I don't use fvexpand directly either. I discovered this behavior when troubleshooting some unintended coefficients popping up in a regression I was running.

      Comment


      • #4
        What version of Stata are you running? I'm not able to recreate your results.
        Code:
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . fvexpand 1.foreign#0.rep78#c.price
        
        . return list
        
        macros:
                      r(fvops) : "true"
                    r(varlist) : "1o.foreign#0o.rep78#co.price"
        
        . fvexpand  1.foreign#1.rep78
        
        . return list
        
        macros:
                      r(fvops) : "true"
                    r(varlist) : "1o.foreign#1o.rep78"
        
        . fvexpand 1.foreign#0.rep78#c.price 1.foreign#1.rep78
        
        . return list
        
        macros:
                      r(fvops) : "true"
                    r(varlist) : "1o.foreign#0o.rep78#co.price 1o.foreign#1o.rep78"
        
        . about
        
        Stata/SE 15.1 for Mac (64-bit Intel)
        Revision 15 Oct 2018

        Comment


        • #5
          William Lisowski I'm running Stata/SE 14.2 for Mac (64-bit Intel). It seems they've improved this behavior. Good to know! Thanks for the replication.

          Comment


          • #6
            Ah, it might be related to this change:


            7. Factor variables now work more like you would expect they would

            Consider fitting a model with the terms
            Code:
            . 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.

            Comment

            Working...
            X