Announcement

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

  • Interaction expansion (xi) and variable list (vl) together

    Hi,

    my question is about the possibility of apply xi: prefix, along with, macro variable $vlcategorical, in arima, a Stata command that does not allow factor variables.

    they does not seem to glue.


    Code:
    . clear
    
    . webuse auto
    (1978 automobile data)
    
    . gen t=_n
    
    * I adapted auto daatset, just to facilitate reproducibility.
    . tsset t
    
    Time variable: t, 1 to 74
            Delta: 1 unit
    
    . vl set
    . vl list vlcategorical
    
    ------------------------------------------------
    Variable | Macro           Values         Levels
    ---------+--------------------------------------
       rep78 | $vlcategorical  integers >=0        5
     foreign | $vlcategorical  0 and 1             2
    ------------------------------------------------
    
    * in this case xi: returns a error
    . xi: arima price i.($vlcategorical)
    varlist required
    r(100);
    
    
    
    * in this case xi: expands only the first variable (rep78)
    . xi: arima price i.$vlcategorical
    i.rep78           _Irep78_1-5         (naturally coded; _Irep78_1 omitted)
    
    omitted output
    any clue how to use xi: and vl, simultaneously?

    thanks

  • #2
    As you have discovered, unlike factor variable notation in which i. will distribute over a list of variables enclosed in parentheses, -xi- does not do that. So to accomplish what you want, you need to do that distribution yourself:

    Code:
    local ivarlist: subinstr global vlcategorical " " " i.", all
    local ivarlist i.`ivarlist'
    xi: arima price `ivarlist'

    Comment


    • #3
      very ingenious, thks.

      Comment


      • #4
        You can also use the command fvunab to distribute the i. operator using the factor-variable notation and store it into a local macro.
        Code:
        fvunab ivarlist : i.($vlcategorical)
        Here it is in action, using the above example setup:
        Code:
        sysuse auto
        generate t = _n
        tsset t
        vl set
        vl list vlcategorical
        fvunab ivarlist : i.($vlcategorical)
        macro list _ivarlist
        xi: arima price `ivarlist'

        Comment

        Working...
        X