@@ -157,7 +157,7 @@ Use :class:`~diff_diff.MultiPeriodDiD` when:
157157
158158 event = MultiPeriodDiD()
159159 results = event.fit(data, outcome = ' y' , treatment = ' treated' ,
160- time = ' period' , unit = ' unit_id' , reference_period = - 1 )
160+ time = ' period' , unit = ' unit_id' , reference_period = 2 )
161161
162162 # Visualize
163163 plot_event_study(results)
@@ -205,10 +205,12 @@ Use :class:`~diff_diff.SyntheticDiD` when:
205205
206206.. code-block :: python
207207
208- from diff_diff import SyntheticDiD
208+ from diff_diff import SyntheticDiD, generate_did_data
209209
210+ # SyntheticDiD requires block treatment (constant within units)
211+ block_data = generate_did_data(n_units = 40 , n_periods = 10 , treatment_effect = 2.0 )
210212 sdid = SyntheticDiD()
211- results = sdid.fit(data , outcome = ' y ' , unit = ' unit_id ' ,
213+ results = sdid.fit(block_data , outcome = ' outcome ' , unit = ' unit ' ,
212214 time = ' period' , treatment = ' treated' )
213215
214216 # View the unit weights
@@ -412,7 +414,7 @@ Use :class:`~diff_diff.BaconDecomposition` when:
412414
413415- You want to **diagnose ** whether TWFE is biased in your staggered setting
414416- You need to see which 2x2 comparisons drive the TWFE estimate
415- - You want to check for negative weights from forbidden comparisons
417+ - You want to check whether later-vs-earlier or already-treated-as-control comparisons carry substantial weight
416418
417419Goodman-Bacon (2021) decomposes the TWFE estimate into a weighted average of
418420all 2x2 DiD comparisons and their weights.
@@ -423,7 +425,7 @@ all 2x2 DiD comparisons and their weights.
423425
424426 bacon = BaconDecomposition()
425427 results = bacon.fit(data, outcome = ' y' , unit = ' unit_id' ,
426- time = ' period' , first_treat = ' treated ' )
428+ time = ' period' , first_treat = ' first_treat ' )
427429 results.print_summary()
428430
429431 # Visualize the decomposition
@@ -535,14 +537,18 @@ For panel data, always cluster at the unit level unless you have a strong reason
535537
536538.. code-block :: python
537539
540+ from diff_diff import generate_did_data
541+
542+ panel = generate_did_data(n_units = 200 , n_periods = 10 , treatment_effect = 2.0 )
543+
538544 # Good: Cluster at unit level for panel data
539- did = DifferenceInDifferences(cluster = ' unit_id ' )
540- results = did.fit(data , outcome = ' y ' , treatment = ' treated' ,
545+ did = DifferenceInDifferences(cluster = ' unit ' )
546+ results = did.fit(panel , outcome = ' outcome ' , treatment = ' treated' ,
541547 time = ' post' )
542548
543549 # Better for few clusters: Wild bootstrap
544- did = DifferenceInDifferences(inference = ' wild_bootstrap' , cluster = ' state ' )
545- results = did.fit(data , outcome = ' y ' , treatment = ' treated' ,
550+ did = DifferenceInDifferences(inference = ' wild_bootstrap' , cluster = ' unit ' )
551+ results = did.fit(panel , outcome = ' outcome ' , treatment = ' treated' ,
546552 time = ' post' )
547553
548554 When in Doubt
0 commit comments