PanelOLS
(dependent, exog, *, weights=None, entity_effects=False, time_effects=False, other_effects=None)[source]¶One and twoway fixed effects estimator for panel data
Parameters: 


Notes
Many models can be estimated. The most common included entity effects and can be described
where \(\alpha_i\) is included if entity_effects=True
.
Time effect are also supported, which leads to a model of the form
where \(\gamma_i\) is included if time_effects=True
.
Both effects can be simultaneously used,
Additionally , arbitrary effects can be specified using categorical variables.
If both entity_effect
and``time_effects`` are False
, and no other
effects are included, the model reduces to PooledOLS
.
Model supports at most 2 effects. These can be entitytime, entityother, timeother or 2 other.
entity_effects
¶Flag indicating whether entity effects are included
fit
(*, use_lsdv=False, cov_type='unadjusted', debiased=True, auto_df=True, count_effects=True, **cov_config)[source]¶Estimate model parameters
Parameters: 


Returns:  results – Estimation results 
Return type: 
Examples
>>> from linearmodels import PanelOLS
>>> mod = PanelOLS(y, x, entity_effects=True)
>>> res = mod.fit(cov_type='clustered', cluster_entity=True)
Notes
Three covariance estimators are supported:
clusters
 Input containing containing 1 or 2 variables.
Clusters should be integer values, although other types will
be coerced to integer values by treating as categorical variablescluster_entity
 Boolean flag indicating to use entity
clusterscluster_time
 Boolean indicating to use time clusterskernel
 One of the supported kernels (bartlett, parzen, qs).
Default is Bartlett’s kernel, which is produces a covariance
estimator similar to the NeweyWest covariance estimator.bandwidth
 Bandwidth to use when computing the kernel. If
not provided, a naive default is used.formula
¶Formula used to construct the model
from_formula
(formula, data, *, weights=None, other_effects=None)[source]¶Create a model from a formula
Parameters: 


Returns:  model – Model specified using the formula 
Return type: 
Examples
>>> from linearmodels import PanelOLS
>>> mod = PanelOLS.from_formula('y ~ 1 + x1 + EntityEffects', panel_data)
>>> res = mod.fit(cov_type='clustered', cluster_entity=True)
has_constant
¶Flag indicating the model a constant or implicit constant
not_null
¶Locations of nonmissing observations
other_effects
¶Flag indicating whether other (generic) effects are included
predict
(params, *, exog=None, data=None, eval_env=4)¶Predict values for additional data
Parameters: 


Returns:  predictions – Fitted values from supplied data and parameters 
Return type:  DataFrame 
Notes
If data is not None, then exog must be None. Predictions from models constructed using formulas can be computed using either exog, which will treat these are arrays of values corresponding to the formulaprocessed data, or using data which will be processed using the formula used to construct the values corresponding to the original model specification.
reformat_clusters
(clusters)¶Reformat cluster variables
Parameters:  clusters (arraylike) – Values to use for variance clustering 

Returns:  reformatted – Original data with matching axis and observation dropped where missing in the model data. 
Return type:  PanelData 
Notes
This is exposed for testing and is not normally needed for estimation
time_effects
¶Flag indicating whether time effects are included
RandomEffects
(dependent, exog, *, weights=None)[source]¶Oneway Random Effects model for panel data
Parameters: 


Notes
The model is given by
where \(u_i\) is a shock that is independent of \(x_{it}\) but common to all entities i.
formula
¶Formula used to construct the model
from_formula
(formula, data, *, weights=None)[source]¶Create a model from a formula
Parameters: 


Returns:  model – Model specified using the formula 
Return type: 
Notes
Unlike standard patsy, it is necessary to explicitly include a constant using the constant indicator (1)
Examples
>>> from linearmodels import RandomEffects
>>> mod = RandomEffects.from_formula('y ~ 1 + x1', panel_data)
>>> res = mod.fit()
has_constant
¶Flag indicating the model a constant or implicit constant
not_null
¶Locations of nonmissing observations
predict
(params, *, exog=None, data=None, eval_env=4)¶Predict values for additional data
Parameters: 


Returns:  predictions – Fitted values from supplied data and parameters 
Return type:  DataFrame 
Notes
If data is not None, then exog must be None. Predictions from models constructed using formulas can be computed using either exog, which will treat these are arrays of values corresponding to the formulaprocessed data, or using data which will be processed using the formula used to construct the values corresponding to the original model specification.
reformat_clusters
(clusters)¶Reformat cluster variables
Parameters:  clusters (arraylike) – Values to use for variance clustering 

Returns:  reformatted – Original data with matching axis and observation dropped where missing in the model data. 
Return type:  PanelData 
Notes
This is exposed for testing and is not normally needed for estimation
BetweenOLS
(dependent, exog, *, weights=None)[source]¶Between estimator for panel data
Parameters: 


Notes
The model is given by
where \(\bar{z}\) is the timeaverage.
fit
(*, reweight=False, cov_type='unadjusted', debiased=True, **cov_config)[source]¶Estimate model parameters
Parameters: 


Returns:  results – Estimation results 
Return type: 
Examples
>>> from linearmodels import BetweenOLS
>>> mod = BetweenOLS(y, x)
>>> res = mod.fit(cov_type='robust')
Notes
Three covariance estimators are supported:
clusters
 Input containing containing 1 or 2 variables.
Clusters should be integer values, although other types will
be coerced to integer values by treating as categorical variablesWhen using a clustered covariance estimator, all cluster ids must be identical within an entity.
formula
¶Formula used to construct the model
from_formula
(formula, data, *, weights=None)[source]¶Create a model from a formula
Parameters: 


Returns:  model – Model specified using the formula 
Return type: 
Notes
Unlike standard patsy, it is necessary to explicitly include a constant using the constant indicator (1)
Examples
>>> from linearmodels import BetweenOLS
>>> mod = BetweenOLS.from_formula('y ~ 1 + x1', panel_data)
>>> res = mod.fit()
has_constant
¶Flag indicating the model a constant or implicit constant
not_null
¶Locations of nonmissing observations
predict
(params, *, exog=None, data=None, eval_env=4)¶Predict values for additional data
Parameters: 


Returns:  predictions – Fitted values from supplied data and parameters 
Return type:  DataFrame 
Notes
If data is not None, then exog must be None. Predictions from models constructed using formulas can be computed using either exog, which will treat these are arrays of values corresponding to the formulaprocessed data, or using data which will be processed using the formula used to construct the values corresponding to the original model specification.
reformat_clusters
(clusters)¶Reformat cluster variables
Parameters:  clusters (arraylike) – Values to use for variance clustering 

Returns:  reformatted – Original data with matching axis and observation dropped where missing in the model data. 
Return type:  PanelData 
Notes
This is exposed for testing and is not normally needed for estimation
FirstDifferenceOLS
(dependent, exog, *, weights=None)[source]¶First difference model for panel data
Parameters: 


Notes
The model is given by
fit
(*, cov_type='unadjusted', debiased=True, **cov_config)[source]¶Estimate model parameters
Parameters:  

Returns:  results – Estimation results 
Return type: 
Examples
>>> from linearmodels import FirstDifferenceOLS
>>> mod = FirstDifferenceOLS(y, x)
>>> res = mod.fit(cov_type='robust')
>>> res = mod.fit(cov_type='clustered', cluster_entity=True)
Notes
Three covariance estimators are supported:
clusters
 Input containing containing 1 or 2 variables.
Clusters should be integer values, although other types will
be coerced to integer values by treating as categorical variablescluster_entity
 Boolean flag indicating to use entity
clusterskernel
 One of the supported kernels (bartlett, parzen, qs).
Default is Bartlett’s kernel, which is produces a covariance
estimator similar to the NeweyWest covariance estimator.bandwidth
 Bandwidth to use when computing the kernel. If
not provided, a naive default is used.When using a clustered covariance estimator, all cluster ids must be identical within a first difference. In most scenarios, this requires ids to be identical within an entity.
formula
¶Formula used to construct the model
from_formula
(formula, data, *, weights=None)[source]¶Create a model from a formula
Parameters: 


Returns:  model – Model specified using the formula 
Return type: 
Notes
Unlike standard patsy, it is necessary to explicitly include a constant using the constant indicator (1)
Examples
>>> from linearmodels import FirstDifferenceOLS
>>> mod = FirstDifferenceOLS.from_formula('y ~ x1', panel_data)
>>> res = mod.fit()
has_constant
¶Flag indicating the model a constant or implicit constant
not_null
¶Locations of nonmissing observations
predict
(params, *, exog=None, data=None, eval_env=4)¶Predict values for additional data
Parameters: 


Returns:  predictions – Fitted values from supplied data and parameters 
Return type:  DataFrame 
Notes
If data is not None, then exog must be None. Predictions from models constructed using formulas can be computed using either exog, which will treat these are arrays of values corresponding to the formulaprocessed data, or using data which will be processed using the formula used to construct the values corresponding to the original model specification.
reformat_clusters
(clusters)¶Reformat cluster variables
Parameters:  clusters (arraylike) – Values to use for variance clustering 

Returns:  reformatted – Original data with matching axis and observation dropped where missing in the model data. 
Return type:  PanelData 
Notes
This is exposed for testing and is not normally needed for estimation
PooledOLS
(dependent, exog, *, weights=None)[source]¶Pooled coefficient estimator for panel data
Parameters: 


Notes
The model is given by
fit
(*, cov_type='unadjusted', debiased=True, **cov_config)[source]¶Estimate model parameters
Parameters:  

Returns:  results – Estimation results 
Return type: 
Examples
>>> from linearmodels import PooledOLS
>>> mod = PooledOLS(y, x)
>>> res = mod.fit(cov_type='clustered', cluster_entity=True)
Notes
Four covariance estimators are supported:
clusters
 Input containing containing 1 or 2 variables.
Clusters should be integer values, although other types will
be coerced to integer values by treating as categorical variablescluster_entity
 Boolean flag indicating to use entity
clusterscluster_time
 Boolean indicating to use time clusterskernel
 One of the supported kernels (bartlett, parzen, qs).
Default is Bartlett’s kernel, which is produces a covariance
estimator similar to the NeweyWest covariance estimator.bandwidth
 Bandwidth to use when computing the kernel. If
not provided, a naive default is used.formula
¶Formula used to construct the model
from_formula
(formula, data, *, weights=None)[source]¶Create a model from a formula
Parameters: 


Returns:  model – Model specified using the formula 
Return type: 
Notes
Unlike standard patsy, it is necessary to explicitly include a constant using the constant indicator (1)
Examples
>>> from linearmodels import PooledOLS
>>> mod = PooledOLS.from_formula('y ~ 1 + x1', panel_data)
>>> res = mod.fit()
has_constant
¶Flag indicating the model a constant or implicit constant
not_null
¶Locations of nonmissing observations
predict
(params, *, exog=None, data=None, eval_env=4)[source]¶Predict values for additional data
Parameters: 


Returns:  predictions – Fitted values from supplied data and parameters 
Return type:  DataFrame 
Notes
If data is not None, then exog must be None. Predictions from models constructed using formulas can be computed using either exog, which will treat these are arrays of values corresponding to the formulaprocessed data, or using data which will be processed using the formula used to construct the values corresponding to the original model specification.
reformat_clusters
(clusters)[source]¶Reformat cluster variables
Parameters:  clusters (arraylike) – Values to use for variance clustering 

Returns:  reformatted – Original data with matching axis and observation dropped where missing in the model data. 
Return type:  PanelData 
Notes
This is exposed for testing and is not normally needed for estimation
FamaMacBeth
(dependent, exog, *, weights=None)[source]¶Pooled coefficient estimator for panel data
Parameters: 


Notes
The model is given by
The FamaMacBeth estimator is computed by performing T regressions, one for each time period using all available entity observations. Denote the estimate of the model parameters as \(\hat{\beta}_t\). The reported estimator is then
While the model does not explicitly include timeeffects, the implementation based on regressing all observation in a single time period is “asif” time effects are included.
Parameter inference is made using the set T parameter estimates using
either the standard covariance estimator or a kernelbased covariance,
depending on cov_type
.
fit
(cov_type='unadjusted', debiased=True, **cov_config)[source]¶Estimate model parameters
Parameters:  

Returns:  results – Estimation results 
Return type: 
Examples
>>> from linearmodels import FamaMacBeth
>>> mod = FamaMacBeth(y, x)
>>> res = mod.fit(cov_type='kernel', kernel='Parzen')
Notes
Four covariance estimators are supported:
kernel
 One of the supported kernels (bartlett, parzen, qs).
Default is Bartlett’s kernel, which is implements the the
NeweyWest covariance estimator.bandwidth
 Bandwidth to use when computing the kernel. If
not provided, a naive default is used.formula
¶Formula used to construct the model
from_formula
(formula, data, *, weights=None)[source]¶Create a model from a formula
Parameters: 


Returns:  model – Model specified using the formula 
Return type: 
Notes
Unlike standard patsy, it is necessary to explicitly include a constant using the constant indicator (1)
Examples
>>> from linearmodels import BetweenOLS
>>> mod = FamaMacBeth.from_formula('y ~ 1 + x1', panel_data)
>>> res = mod.fit()
has_constant
¶Flag indicating the model a constant or implicit constant
not_null
¶Locations of nonmissing observations
predict
(params, *, exog=None, data=None, eval_env=4)¶Predict values for additional data
Parameters: 


Returns:  predictions – Fitted values from supplied data and parameters 
Return type:  DataFrame 
Notes
If data is not None, then exog must be None. Predictions from models constructed using formulas can be computed using either exog, which will treat these are arrays of values corresponding to the formulaprocessed data, or using data which will be processed using the formula used to construct the values corresponding to the original model specification.
reformat_clusters
(clusters)¶Reformat cluster variables
Parameters:  clusters (arraylike) – Values to use for variance clustering 

Returns:  reformatted – Original data with matching axis and observation dropped where missing in the model data. 
Return type:  PanelData 
Notes
This is exposed for testing and is not normally needed for estimation