cast of non-full rank regression in the first-step regression of FamaMacBeth
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Start in model.py at FamaMacBeth.fit.single, especially the full-rank check around lines 2755–2761. Reproduce the 1935 case with the supplied grunfeld data and compare the current result with the issue’s np.linalg.lstsq example. Done means the rank-deficient group produces the stated coefficients rather than all NaNs, with regression tests covering the behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I found that in the first-step regression of FamaMacBeth function (i.e. FamaMacBeth.fit.single function in line 2755-2761 of model.py), if the exog matrix is not full-rank, the coefficients of time-series regression for that group will be NaN. But when I use Stata/SE 15.1, the coefficients of that collinear variables will be 0, and the coefficients of remaining variables will be the same as for normal regression. So I think that the full rank command on line 2757 may need to be reconsidered......
For example, I use grunfeld data set and create a dummy variable. For those obs with year < 1945, I set dummy variable as 0, and for those obs with year >= 1945, I set dummy variable randomly from 0 to 1.
The subset of the data is:
invest mvalue kstock Dummy Dummy*mvalue Dummy*kstock const
company year
1 1935 317.600010 3078.500000 2.800000 0 0.0 0.0 1
2 1935 209.899990 1362.400000 53.799999 0 0.0 0.0 1
3 1935 33.099998 1170.600000 97.800003 0 0.0 0.0 1
4 1935 40.290001 417.500000 10.500000 0 0.0 0.0 1
5 1935 39.680000 157.700000 183.200000 0 0.0 0.0 1
6 1935 20.360001 197.000000 6.500000 0 0.0 0.0 1
7 1935 24.430000 138.000000 100.200000 0 0.0 0.0 1
8 1935 12.930000 191.500000 1.800000 0 0.0 0.0 1
9 1935 26.629999 290.600010 162.000000 0 0.0 0.0 1
10 1935 2.540000 70.910004 4.500000 0 0.0 0.0 1
In linearmodels package, we will get:
# est = FamaMacBeth(d['invest'], d[['const', 'mvalue', 'kstock', 'Dummy', 'Dummy*mvalue', 'Dummy*kstock']]).fit(cov_type='kernel', kernel='bartlett', bandwidth=5)
# print(est.all_params.iloc[[0], :])
const mvalue kstock Dummy Dummy*mvalue Dummy*kstock
year
1935 NaN NaN NaN NaN NaN NaN
But in Stata/SE 15.1, we will get:
# xtset company year
# asreg invest mvalue kstock dummy dummymvalue dummykstock , fmb newey(5) save(~/Downloads/coff_stata)
_b_mvalue _b_kstock _b_dummy _b_dummymvalue _b_dummykstock _Cons _R2 _adjR2 _TimeVar _obs
.10249786 -.00199479 0 0 0 .3560334 .865262 .7574716 1935 10
The result from Stata is the same as the result directly using np.linalg.lstsq:
const mvalue kstock Dummy Dummy*mvalue Dummy*kstock
year
1935 0.356033 0.102498 -0.001995 0.0 0.0 0.0
So I think the regression for those groups with non-full rank can still be estimated, instead of getting NaN.
The logic of the judgment in the Stata software seems to be to select a certain variable for regression among all collinear variables, and all coefficients of the others are set to 0. I find that the judgment priority may be as follows:
- Non-zero normal variable;
- Constant term;
- the coefficients of the variables wtih all 0 value are naturally set to 0.
Similar issue #176
The data set I use is available below.
grunfeld.csv.zip
- Ngôn ngữ chính
- Python
- Star
- 1.1k
- Fork
- 203
- Merge trung bình
- 3 giờ 26 phút
- Pull request đã merge (30 ngày)
- 115
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bashtage/linearmodels
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
bashtage/linearmodels#832 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
bashtage/linearmodels#831 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
IV: LIML kappa with an endogenous regressor spanned by the instruments, kappa's unit dependence, scale-dependent instrument rank checkCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
bashtage/linearmodels#823 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
bashtage/linearmodels#817 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
bashtage/linearmodels#780 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bashtage/linearmodels
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Claiming namespace `thejakia1`Đang mởnamespace operations
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
EclipseFdn/open-vsx.org#15057 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
FinanceFlash/unvibecode#349 ·
-
Mission statement: why this is free, in the README, Why This Exists and the wiki HomeCó thể đã có người làm @ChiefGyk3D đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ChiefGyk3D/Clouds-Against-Humanity#348 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Perf] Default --vllm-watermark 0.05 for rollouts (hybrid models re-preempt under KV pressure)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
vllm-project/vime#508 ·
Maintainer thường phản hồi trong vòng 4 ngày