Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: ENH PanelAR1: add Prais-Winston for 1st obs, same as Stata #301

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions statsmodels/sandbox/regression/ar_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,31 @@ def __init__(self, endog, exog=None, groups=None):
if not exog is None:
self.exog = exog

self.groups_start = (np.diff(groups)!=0)
self.groups_start = np.concatenate(([True], (np.diff(groups)!=0)))
self.groups_valid = ~self.groups_start

def ar1filter(self, xy, alpha):
#print alpha,
return (xy[1:] - alpha * xy[:-1])[self.groups_valid]
if hasattr(self, 'use_prais'):
#print 'using prais'
transformed = np.zeros_like(xy)
transformed[1:] = (xy[1:] - alpha * xy[:-1])
fac = np.sqrt(1.-min(alpha, 1)**2)
transformed[self.groups_start] = xy[self.groups_start] * fac
return transformed
else:
return (xy[1:] - alpha * xy[:-1])[self.groups_valid[1:]]

def fit_conditional(self, alpha):
y = self.ar1filter(self.endog, alpha)
x = self.ar1filter(self.exog, alpha)
res = OLS(y, x).fit()
return res.ssr #res.llf
return res#-res.llf #res.ssr #res.llf


def fit(self):
alpha0 = 0.1 #startvalue
func = self.fit_conditional
func = lambda alpha: -self.fit_conditional(alpha).llf
fitres = optimize.fmin(func, alpha0)

# fit_conditional only returns ssr for now
Expand Down