English 中文(简体)
A. 加快各州的滚动倒退
原标题:Speeding up rolling regressions in Stata
最佳回答
问题回答

与使用<条码>滚动/代码>和<条码>回归<>条码/代码>相比,“单程”回落速度确实快得多。 以下编码比<编码>滚动<>/代码>快约400倍。 当然,<编码>滚动更为便捷,但如果你只希望有β、甲型、R^2和西格玛^2,那么,就会有trick。

program rolling_beta
    version 11.2
    syntax varlist(numeric), window(real)

    * get dependent and indpendent vars from varlist
    tempvar x y x2 y2 xy xs ys xys x2s y2s covxy varx vary
    tokenize "`varlist "
    generate `y  = `1  
    generate `x  = `2  
    local w = `window  

    * generate products
    generate `xy  = `x *`y 
    generate `x2  = `x *`x 
    generate `y2  = `y *`y 

    * generate cumulative sums
    generate `xs  = sum(`x )
    generate `ys  = sum(`y )
    generate `xys  = sum(`xy )
    generate `x2s  = sum(`x2 )
    generate `y2s  = sum(`y2 )

    * generate variances and covariances
    generate `covxy  = (s`w .`xys  - s`w .`xs *s`w .`ys /`w )/`w 
    generate `varx  = (s`w .`x2s  - s`w .`xs *s`w .`xs /`w )/`w 
    generate `vary  = (s`w .`y2s  - s`w .`ys *s`w .`ys /`w )/`w 

    * generate alpha, beta, r2, s2
    generate beta = `covxy /`varx 
    generate alpha = (s`w .`ys  - beta*s`w .`xs )/`w 
    generate r2 = `covxy *`covxy /`varx /`vary 
    generate s2 = `vary *`w *(1 - r2)/(`w  - 2)

end

。 通常的代码为<代码>36小时,然后与<代码>asreg>/code>在低于<代码>5分钟的同一条。

很明显,per regression大多数时间都是在选择一组观测站以管理回归时,即o(N), 编号为数据集中的观察总数。 似乎有<条码>asreg 在马塔实施。

它将实施一套标准的《非洲人事政策》滚动退步:

bysort permno: asreg mret_rf mkt_rf, wind(month 60)

<代码>permno为公司识别符号mret_rf 每月公司收益减去风险自由率,mkt_rf www.un.org/Depts/DGACM/index_french.htm 标明月份的日期变量的名称和60 滚动窗口数月的大小。

在Stata安装asreg:

ssc install asreg




相关问题
Multi-variate regression using NumPy in Python?

Is it possible to perform multi-variate regression in Python using NumPy? The documentation here suggests that it is, but I cannot find any more details on the topic.

Regressing panel data in SAS

I am now looking at a panel dataset on which I have to regress. Since I only started my Phd this semester together with the econometrics courses I am still new to many statistic applications and ...

Mysql multivariable linear regression

I am trying to do a multivarible (9 variables) linear regression on data in my mysql 5.0 database (the result value field only has 2 possible values, 1 and 0). I ve done some searching and found I ...

scipy linregress function erroneous standard error return?

I have a weird situation with scipy.stats.linregress seems to be returning an incorrect standard error: from scipy import stats x = [5.05, 6.75, 3.21, 2.66] y = [1.65, 26.5, -5.93, 7.96] gradient, ...

How to do a linear regression into a BIRT report?

How to make a linear regression on the chart displayed into your BIRT report. I have x and y data... but I don t see any function on eclipse BIRT to generate the linear regression... Any idea ? Many ...

热门标签