TWFE#

[1]:
from differences import simulate_data, TWFE

see plotto to configure the plots. the .plot() method takes the same arguments as the function mark_plot() in plotto

[2]:
panel_data = simulate_data()  # generate data

panel_data
[2]:
y x0 w cat.0 cat.1 effect cohort intensity
entity time
e0 1900 0.376343 0.160245 3.729827 0 0 0.0 NaN NaN
1901 1.664105 -1.933404 1.691201 0 0 0.0 NaN NaN
1902 -11.229124 -0.056813 1.786326 0 0 0.0 NaN NaN
1903 0.542425 0.810118 1.741609 0 0 0.0 NaN NaN
1904 1.111293 0.101205 0.806004 0 0 0.0 NaN NaN
... ... ... ... ... ... ... ... ... ...
e999 1903 -12.916305 1.355023 0.688025 0 0 0.0 NaN NaN
1904 -7.780740 -0.381267 1.952084 0 0 0.0 NaN NaN
1905 -16.677634 -0.258604 1.801049 0 0 0.0 NaN NaN
1906 0.556390 1.504564 0.616657 0 0 0.0 NaN NaN
1907 -4.153630 0.472740 0.674045 0 0 0.0 NaN NaN

8000 rows × 8 columns

[3]:
twfe = TWFE(
    data=panel_data,
    cohort_name='cohort',
)
[4]:
twfe.fit(
    formula='y',
    cluster_names='entity',
)
[4]:
parameter std_error t_stat p_value lower upper
Intercept 0.170176 0.483307 0.352107 7.247582e-01 -0.777088 1.117439
-6 3.943623 1.100968 3.581961 3.410253e-04 1.785766 6.101481
-5 3.322752 1.025707 3.239476 1.197494e-03 1.312404 5.333100
-4 2.169448 0.901665 2.406047 1.612621e-02 0.402217 3.936679
-3 0.799785 0.736629 1.085737 2.775954e-01 -0.643981 2.243552
-2 2.223513 0.855707 2.598452 9.364502e-03 0.546359 3.900667
0 -0.120740 0.881288 -0.137004 8.910277e-01 -1.848032 1.606552
1 5.291089 0.708303 7.470090 8.015810e-14 3.902840 6.679338
2 12.605998 1.031534 12.220630 0.000000e+00 10.584228 14.627768
3 21.453005 0.873314 24.565050 0.000000e+00 19.741341 23.164670
4 34.619623 1.321403 26.199132 0.000000e+00 32.029720 37.209526
5 43.410681 1.207994 35.936172 0.000000e+00 41.043057 45.778306
6 54.668145 1.478442 36.976859 0.000000e+00 51.770451 57.565838
7 67.229564 1.357234 49.534260 0.000000e+00 64.569435 69.889693
[5]:
twfe.plot()
[5]: