Announcement

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

  • Problem with factor variable and "maxvar too small" error

    Hi everyone,

    I'm running a Bayesian model similar to this one

    Code:
    use http://www.stata-press.com/data/r15/usmacro
    
    generate id=_n
    
    fvset base none id
    
    set seed 12345
    
    bayesmh fedfunds = (({state:}==1)*{mu1}+({state:}==2)*{mu2}), likelihood(normal({sig2})) redefine(state:i.id) prior({state:}, index({p1}, (1-{p1}))) prior({p1}, uniform(0, 1)) prior({mu1} {mu2}, normal(0, 100)) prior({sig2}, igamma(0.1, 0.1)) init({p1} 0.5 {mu1} 1 {mu2} 1 {sig2} 1 {state:} 1) block({sig2}, gibbs) block({p1}) block({mu1}{mu2}) exclude({state:}) dots

    My data set is a series of daily returns (in %) of a stock market index, which is similar to the "y" variable - fedfunds, in the example above. The column "Date" is formatted as "YYYYMMDD", starting from 02/08/2000 to 21/02/2020, for a total of 4,722 observations
    Date return
    20000802 0.0180206794682423
    20000804 0.0176049526020507
    ................
    20200220 0.0100887204444635
    20200221 -0.00537238975408516
    When I run the same code as above, only replacing "return" with "fedfunds", I get the "maxvar" error

    Code:
    generate id=_n
    
    fvset base none id
    
    set seed 12345
    
    bayesmh return = (({state:}==1)*{mu1}+({state:}==2)*{mu2}), likelihood(normal({sig2})) redefine(state:i.id) prior({state:}, index({p1}, (1-{p1}))) prior({p1}, uniform(0, 1)) prior({mu1} {mu2}, normal(0, 100)) prior({sig2}, igamma(0.1, 0.1)) init({p1} 0.5 {mu1} 1 {mu2} 1 {sig2} 1 {state:} 1) block({sig2}, gibbs) block({p1}) block({mu1}{mu2}) exclude({state:}) dots
    
    maxvar too small
        You have attempted to use an interaction with too many levels or attempted to fit a model with too many variables.  You need to increase maxvar; it is
        currently 2048.  Use set maxvar; see help maxvar.
    
        If you are using factor variables and included an interaction that has lots of missing cells, either increase maxvar or set emptycells drop to reduce the
        required matrix size; see help set emptycells.
    
        If you are using factor variables, you might have accidentally treated a continuous variable as a categorical, resulting in lots of categories.  Use the c.
        operator on such variables.
    I tried each of the 3 default suggestions by Stata but it's not working. I cannot set "maxvar" because I'm using Stata/IC 15.1. I don't have any empty cells in my factor variable, neither do I accidentally treated a continuous variable as a categorical.

    I think this is about how I set my factor variable "id", rather than the maxvar limit itself.

    I would really appreciate any help I can get!

    Best,
    Last edited by John Zoey; 24 Feb 2020, 10:44.

  • #2
    You did not get a quick answer. You will increase your chances of helpful answer by following the FAQ on asking questions. Also, it is good practice to use line continuation marks /// instead of having extremely long lines. Your bayesmh statement is extremely hard to read.

    I don't use this procedure, but you are defining id such that it is a separate value for each observation in your data set. This is likely a mistake. If you are interacting it with anything, you are generating many more parameters than you have observations.

    Comment

    Working...
    X