Skip to content

linearmodels/first-difference-constant

Rule first-difference-constant
Pack linearmodels
Severity error
Fix unsafe, with xpd check --fix --unsafe-fixes
Library versions every version

FirstDifferenceOLS takes no constant, so a 1 term or add_constant raises ValueError. Take the constant out, because the difference removes the intercept.

model = FirstDifferenceOLS.from_formula("lwage ~ 1 + hours", data)
model = FirstDifferenceOLS(y, sm.add_constant(X))
model = FirstDifferenceOLS.from_formula("lwage ~ hours", data)
model = FirstDifferenceOLS(y, X)

The rule reports a 1 term in a formula of FirstDifferenceOLS, and add_constant(...) as its exog. A first difference removes everything that is constant over time, so the model refuses a constant.

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

With the unsafe fix, the 1 term is taken out of the formula, and add_constant(X) becomes X. The call raised before the fix. A formula whose only term is the 1 has no fix.

Both forms raised ValueError: Constants are not allowed in first difference regressions. on 7.1 and 7.0.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

FirstDifferenceOLS takes no constant, and $F has a 1 term. linearmodels 7.1 raises ValueError with "Constants are not allowed in first difference regressions." Take the 1 out, because the difference removes the intercept.

Browse the other rules of the linearmodels pack.