mcaceresb / stata-gtools

Faster implementation of Stata's collapse, reshape, xtile, egen, isid, and more using C plugins
https://gtools.readthedocs.io
MIT License
182 stars 38 forks source link

Rolling-window regression like rangestat (reg)? #70

Closed flcong closed 4 years ago

flcong commented 4 years ago

What would you like gtools to add or change (and why)? I've been using rangestat to estimate rolling-window regressions, specifically for estimating factor betas, but rangestat seems still a bit slow when running on my laptop, perhaps because it is written in Mata, not C. I'm aware that gstat transform can be used to calculate rolling-window statistics, but it does not support rolling-window regressions, right?

Please include a specific suggestion Add rolling-window regression in gstat transform, like rangestat (reg) varlist, interval().

Additional context

mcaceresb commented 4 years ago

The short version is that while I like this idea, and would like to add this to gtools, I don't have an ETA as I expect it would be a fair amount of work.

The longer version: I also got a request for this about a year ago. A few months later I added various regression models by group; the idea was, in part, that they would be a building blocks for the rolling regression commands, The regression models I coded are in beta but they're a lot more than what I need for rolling regressions. The core functionality is there and works just fine.

The issue, though, is that gstats transform (range) is is actually one of the more complicated functions I've implemented (in large part due to the range of options it has). I expect that combining it with even bare-bones OLS would be a lot of work... I've now started a PhD so gtools has been taking a back seat in terms of priority. I'll keep adding functionality as I can, but I don't have an ETA. Sorry!

flcong commented 4 years ago

Thank you very much for the quick and detailed response. I understand that the code becomes more and more complicated as more and more features are added. I'll try to write Mata to implement this. Hopefully it is faster than rangestat if I use matrix form.