Questions tagged [linearmodels]

A python package which provides estimation and inference in some common linear models including panel data and instrumental variables estimators. For questions related to implementation or interpretation of a linearmodels estimator.

linearmodels is a package which provides some more complex linear estimation techniques to Python, based around numpy and pandas.

Common linear models such as Two-stage least squares, Generalized Method of Moments etc. are missing from the popular statsmodels package and this package fills that gap.

141 questions
2
votes
1 answer

Errors attempting to use linearmodels.panel.PanelOLS entity effects (not time effects)

I have a Pandas DataFrame like (abridged): age gender control county 11877 67.0 F 0 AL-Calhoun 11552 60.0 F 0 AL-Coosa 11607 60.0 F 0 AL-Talladega 13821 NaN NaN 1 AL-Mobile 11462 59.0 F 0 AL-Dale I want to run a linear…
OJT
  • 887
  • 1
  • 10
  • 26
2
votes
0 answers

Python panel data regression with more than two fixed effects

I have a panel database and would like to run a regression considering fixed effects. When using Panel.Ols, two fixed effects work without problems. My code looks like this: df['countyCode'] = pd.Categorical(df['countyCode']) df['state'] =…
2
votes
1 answer

Is there a way to derive the intercept of the firm fixed effect from the Python PanelOLS model?

I am in the process of estimating the fixed effect of panel data using the Python statsmodel package. First, the data used in the analysis include X and Y observed over time with several companies. Below are some examples from the actual data, but…
2
votes
1 answer

How to cluster by entity and year, in IV2SLS with linearmodels?

I am working on a panel model of African countries, with their democracy scores, log(gdp per capita) with 3 lags, and log(rain) amounts, also with three lags. I am trying to us IV2SLS to find the economic shocks in log(gdp per capita) (and its lags)…
Demosthenes
  • 111
  • 1
  • 9
2
votes
1 answer

linear models: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject"

I get this error when I try to import linearmodels: "numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject" I run Anaconda, python 3.8.8 on Windows 10. It is a fresh installation of Anaconda…
Martien Lubberink
  • 2,614
  • 1
  • 19
  • 31
2
votes
1 answer

Panel regression gives error "exog does not have full column rank"

I am trying to estimate a panel regression (see: https://bashtage.github.io/linearmodels/doc/panel/examples/examples.html) My data is formatted like that (thats just an example snippet; in the orginal file there are 11 columns plus the timestamp and…
CSBossmann
  • 193
  • 2
  • 11
2
votes
1 answer

ModuleNotFoundError for module 'linearmodels'

I want to perform an OLS Panel Regression import pandas as pd import numpy as np import statsmodels.api as sm from linearmodels.datasets import wage_panel from linearmodels.panel import PanelOLS data = wage_panel.load() But I get this…
CSBossmann
  • 193
  • 2
  • 11
2
votes
0 answers

Performing a Mediation Analysis for Fixed Effects Model in Python

I asked the same question here but have not received an answer for a week now, probably because its more of a coding than statistics question I want to perform a mediation analysis with a fixed effects model as base model in python. I know, that you…
TiTo
  • 833
  • 2
  • 7
  • 28
2
votes
8 answers

from_formula() missing 2 required positional arguments: 'formula' and 'data'

I am getting positional arguments error for the ols function under statsmodels.formula.api have tried for statsmodels.regression.linear_model and changing OLS to ols and vice-versa. import statsmodels.regression.linear_model as sm X =…
2
votes
1 answer

Multicollinearity in Panel Data in Python

I am used to using Stata or R to do linear regression models but I am transitioning more workflow over to Python. The useful thing about these two programs is that they intuitively know that you do not care about all of the entity- or time-fixed…
Lucas H
  • 927
  • 8
  • 15
2
votes
1 answer

The 4 outputs of a linear model in R

In R, after creating a linear model using the function model <- lm() and plotting it using plot(model), you will get back 4 graphs each displaying your model differently. Can anyone explain what these graphs mean?
JohnBanter
  • 49
  • 3
2
votes
1 answer

How to do predict() for linearmodels

Below is Fixed Effect Estimation python code by linearmodels module from here. from linearmodels import PanelOLS mod = PanelOLS(y_train, x_train, entity_effects=True) res = mod.fit(cov_type='clustered', cluster_entity=True) How can we do…
ybdesire
  • 1,593
  • 1
  • 20
  • 35
2
votes
1 answer

'Array is not a python function' Error when building simple linear model in keras

I am trying to build a simple linear model using keras as following: lin_model = Sequential([ Lambda(x_train, input_shape=(1,28,28)), Flatten(), Dense(10, activation='softmax') ]) but I keep getting the following…
A_Matar
  • 2,210
  • 3
  • 31
  • 53
1
vote
1 answer

Constrain linear model in R so that output matches with MINITAB

I am trying to recreate in R an example analysis done in a textbook in MINITAB. Below is my code for saving the data and fitting the model. joint <- c("beveled", "butt", "beveled", "butt", "beveled", "beveled", "lap", "beveled", "butt",…
spencergw
  • 157
  • 5
1
vote
0 answers

Calculate Newey West adjusted t-statistic with statsmodel libary after FamaMac-Beth regression

I am currently running a multivariate Fama-MacBeth regression (Fama and MacBeth, 1973) on a dataset containing the risk factors MRI, SMB and HML in this example. In my analysis, I need to exclude certain variables (in this example HML) before a…
1
2
3
9 10