Chatpter 5 (cont.). Advanced Causal Inference in Julia
import Pkg;
Pkg.add(["DiffinDiffs", "RegressionDiscontinuity", "SynthControl", "Dates", "Plots"]);[32m[1m Resolving[22m[39m package versions...
[32m[1m No Changes[22m[39m to `~/.julia/environments/v1.11/Project.toml`
[32m[1m No Changes[22m[39m to `~/.julia/environments/v1.11/Manifest.toml`Instrumental Variable
using DataFrames, RDatasets, FixedEffectModels
df = dataset("plm", "Cigar")
first(df, 5)5×9 DataFrame
Int64
Int64
Float64
Float64
Float64
Float64
Float64
Float64
Float64
1
1
63
28.6
3383.0
2236.5
30.6
1558.3
93.9
26.1
2
1
64
29.8
3431.0
2276.7
31.0
1684.07
95.4
27.5
3
1
65
29.8
3486.0
2327.5
31.5
1809.84
98.5
28.9
4
1
66
31.5
3524.0
2369.7
32.4
1915.16
96.4
29.5
5
1
67
31.6
3533.0
2393.7
33.4
2023.55
95.5
29.6
For example, if we have an instrumental variable Price predicting CPI which predicts Sales (theoretically incorrect, just for illustration), the formula here should be:
# DV ~ exogenous variables + (endogenous variables ~ instrumental variables) + fe(fixedeffect variable)
reg(df, @formula(Sales ~ NDI + (CPI ~ Price ) + fe(State)))Difference-in-difference
Regression Discontinuity
Synthetic Control
897×3 DataFrame872 rows omitted
String
Date
Float64
1
Australia
2009-01-01
1.04
2
Austria
2009-01-01
-1.53
3
Belgium
2009-01-01
-1.15
4
Canada
2009-01-01
-2.28
5
Denmark
2009-01-01
-1.42
6
Finland
2009-01-01
-6.8
7
France
2009-01-01
-1.67
8
Germany
2009-01-01
-4.49
9
Greece
2009-01-01
-4.74
10
Iceland
2009-01-01
-7.61
11
Ireland
2009-01-01
-0.34
12
Italy
2009-01-01
-2.75
13
Japan
2009-01-01
-4.88
⋮
⋮
⋮
⋮
886
Italy
2018-07-01
-0.82
887
Japan
2018-07-01
9.54
888
Luxembourg
2018-07-01
28.41
889
Netherlands
2018-07-01
10.69
890
New Zealand
2018-07-01
24.06
891
Norway
2018-07-01
12.82
892
Portugal
2018-07-01
2.23
893
Spain
2018-07-01
5.74
894
Sweden
2018-07-01
22.48
895
Switzerland
2018-07-01
14.35
896
United Kingdom
2018-07-01
15.72
897
United States
2018-07-01
19.32

SyntheticDiD
Last updated
Was this helpful?