Skip to content

Standard errors of the estimators when IV2SLS is used as OLS #187

@spring-haru

Description

@spring-haru

I compared the results of Wages of Married Women at this page, using linearmodels, statsmodels and R. Naturally, all of them give the same estimates of the const and educ. However, the standard errors of the estimators in linearmodels are (slightly) differenit from those in statsmodels and R, which give basically the identical values (after rounding). I also "manually" calculated them in each case of linearmodels and statsmodels. The results are identical, and basically the same as in statsmodels. It seems to suggest that there is something "funny" in the standard errors of the estimators linearmodels. I wonder if you can help me in understanding those results.

Standard Errors of const
linearmodels: 0.184793
statsmodelss: 0.185226
R: 0.18522590

Standard Errors of educ
linearmodels: 0.014366
statsmodelss: 0.014400
R: 0.01439985

Python Code

import numpy as np
from linearmodels.iv import IV2SLS
from linearmodels.datasets import mroz
from statsmodels.formula.api import ols
from statsmodels.api import add_constant

data = mroz.load().dropna()
data = add_constant(data, has_constant='add')

# linearmodels -------
formula_lm = 'np.log(wage) ~ 1+ educ'
result_lm = IV2SLS.from_formula(formula_lm, data).fit(cov_type='unadjusted')
print(result_lm.std_errors)

# Statsmodels -------
formula_sm = 'np.log(wage) ~ educ'
result_sm = ols(formula_sm, data).fit()
print(result_sm.bse)

Manual Calculations

# linearmodels -------------------------------------
# no of observations
n_lm = result_lm.nobs

# residuals
resid_lm = result_lm.resids

# Standard Erros of Regression
SER_lm = np.std(resid_lm, ddof=1) * np.sqrt((n_lm - 1) / (n_lm - 2))

# Standard Errors of Intercept
SE_const_lm = SER_lm / np.std(data.educ, ddof=1) / \
    np.sqrt(n_lm - 1) * np.sqrt(np.mean(data.educ**2))
print(SE_const_lm)

# Standard Errors of educ
SE_educ_lm = SER_lm / np.std(data.educ, ddof=1) / np.sqrt(n_lm - 1)
print(SE_educ_lm)

# statsmodels -------------------------------------
# no of observations
n_sm = result_sm.nobs

# residuals
resid_sm = result_sm.resid

# Standard Erros of Regression
SER_sm = np.std(resid_sm, ddof=1) * np.sqrt((n_sm - 1) / (n_sm - 2))

# Standard Errors of Intercept
SE_const_sm = SER_sm / np.std(data.educ, ddof=1) / \
    np.sqrt(n_sm - 1) * np.sqrt(np.mean(data.educ**2))
print(SE_const_sm)

# Standard Errors of educ
SE_educ_sm = SER_sm / np.std(data.educ, ddof=1) / np.sqrt(n_sm - 1)
print(SE_educ_sm)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions