Announcement

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

  • Fama-MacBeth Command: fm vs xtfmb

    Hi,

    I am implementing the Fama-MacBeth out-of-sample. I am using xtfmb (install ssc xtfmb)

    I have tried to combine it with "rolling" but the output file is empty. Any idea how to implement that?
    Code:
    webuse grunfeld, clear
    
    xtset company year
    
    xtfmb invest mvalue kstock, verbose
    fm invest mvalue kstock
    
    rolling _b _se, window(10) saving(betas, replace) keep(year): xtfmb invest mvalue kstock
    Note that I am open to use the command "fm" that can be found there:
    http://www.kellogg.northwestern.edu/...rogramming.htm


  • #2
    fm is more flexible because it allows for estimates by panel and time. With one dimension, they are the same. If neither work with rolling, it is fairly simple to roll your own. Below is the equivalent of rolling for xtfmb You'll need to change the code in blue to fit your data. Optional things to uncomment are in orange.

    Code:
    webuse grunfeld, clear
    *preserve           // if you want your original data back, uncomment.  otherwise the rolling data will replace it
    statsby _b _se, by(year) : reg invest mvalue kstock
    
    local window=10
    local vars "mvalue kstock"  // independent variables
    qui{
    sum year, meanonly
    local start=r(min)
    local end=`start'+`window'
    local fin=r(max)
    gen _start=.
    gen _end=.
    
    foreach var in `vars' cons {
        gen b_`var'=.
        gen se_`var'=.
        }
    
    local i=1
    while `end'<=`fin' {
         replace _start=`start' in `i'
        replace _end=`end' in `i'
    
        foreach var in `vars' cons {
            qui sum _b_`var' if inrange(year, `start' , `end')
            replace b_`var' = r(mean) in `i'
            replace se_`var'= (r(sd)/sqrt(r(N))) in `i'
            }
        local start=`start'+1
        local end=`end'+1
        local i=`i'+1
    }
    keep _start _end se_* b_*
    drop if _start==.
    }
    *save c:\temp\rolling.dta         //uncomment if you want to save
    
    *restore      //uncomment if you uncommented preserve
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment

    Working...
    X