learn_within_vs_lsdv

source

learn_within_vs_lsdv(
    n_units=30,
    n_periods=6,
    beta=2.0,
    unit_effect_corr=0.8,
    noise_sd=0.5,
    seed=0,
)

Show that within (demeaning) and least-squares dummy variables give the same slope.

Simulates a panel with a unit fixed effect and recovers the slope two ways: the within transformation (demeaning, via absorbed fixed effects) and least-squares dummy variables (one dummy per unit in OLS). By the Frisch-Waugh-Lovell theorem the two slopes are identical for any number of periods — demeaning and unit dummies do the same job.

Parameters

Name Type Description Default
n_units int Panel dimensions (kept modest so LSDV’s one-dummy-per-unit design stays cheap). 30
n_periods int Panel dimensions (kept modest so LSDV’s one-dummy-per-unit design stays cheap). 30
beta float True within-unit slope. 2.0
unit_effect_corr float Correlation between x and the unit effect. 0.8
noise_sd float Idiosyncratic noise standard deviation. 0.5
seed int Random seed. 0

Returns

Name Type Description
SandboxResult df (within vs LSDV vs true slope), fig, summary and topic.

Examples

This sandbox simulates its own panel, so the call needs no DataFrame:

import expdpy as ex

res = ex.learn_within_vs_lsdv()
res.fig