-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Documenter.jl
committed
Apr 17, 2024
1 parent
5b5ea8b
commit 200db06
Showing
15 changed files
with
873 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>IV/2SLS examples · WildBootTests.jl</title><script data-outdated-warner src="../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href="../">WildBootTests.jl</a></span></div><form class="docs-search" action="../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../">Overview</a></li><li><a class="tocitem" href="../OLSexamples/">OLS examples</a></li><li class="is-active"><a class="tocitem" href>IV/2SLS examples</a></li><li><a class="tocitem" href="../exported/">Public functions and types</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>IV/2SLS examples</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>IV/2SLS examples</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/droodman/WildBootTests.jl/blob/master/docs/src/IVexamples.md" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><pre><code class="nohighlight hljs">using WildBootTests, CSV, DataFrames, StatsModels, GLM, Plots | ||
|
||
# specify exactly identified model: regress wage on on tenure, instrumented by union, | ||
# controlling for ttl_exp and collgrad | ||
d = download("http://www.stata-press.com/data/r8/nlsw88.dta", tempname() * ".dta") | ||
df = DataFrame(load(d))[:, [:wage; :tenure; :ttl_exp; :collgrad; :industry; :union]] | ||
dropmissing!(df) | ||
f = @formula(wage ~ 1 + ttl_exp + collgrad) | ||
f = apply_schema(f, schema(f, df)) | ||
resp, predexog = modelcols(f, df) | ||
ivf = @formula(tenure ~ union) | ||
ivf = apply_schema(ivf, schema(ivf, df)) | ||
predendog, inst = modelcols(ivf, df) | ||
|
||
# test that coefficient on tenure = 0, clustering errors by industry | ||
R = [0 0 0 1]; r = [0] | ||
wildboottest(R, r; resp, predexog, predendog, inst, clustid=df.industry) | ||
|
||
# use equal-tailed instead of symmetric p value | ||
wildboottest(R, r; resp, predexog, predendog, inst, clustid=df.industry, ptype=:equaltail) | ||
|
||
# perform bootstrap-c instead of bootstrap-t, as advocated by Young (2019) | ||
wildboottest(R, r; resp, predexog, predendog, inst, clustid=df.industry, bootstrapc=true) | ||
|
||
# Rao/score test without bootstrap | ||
wildboottest(R, r; resp, predexog, predendog, inst, clustid=df.industry, reps=0) | ||
|
||
# Wald test without bootstrap | ||
wildboottest(R, r; resp, predexog, predendog, inst, clustid=df.industry, reps=0, imposenull=false) | ||
|
||
# Anderson-Rubin test that hypothesis holds and instrument is valid | ||
wildboottest(R, r; resp, predexog, predendog, inst, clustid=df.industry, arubin=true) | ||
|
||
# modify model to drop controls and make ttl_exp an instrument | ||
f = @formula(wage ~ 1) | ||
f = apply_schema(f, schema(f, df)) | ||
resp, predexog = modelcols(f, df) | ||
ivf = @formula(tenure ~ collgrad + ttl_exp) | ||
ivf = apply_schema(ivf, schema(ivf, df)) | ||
predendog, inst = modelcols(ivf, df) | ||
|
||
# test same hypothesis in context of LIML regression | ||
R = [0 1]; r = [0] | ||
wildboottest(R, r; resp, predexog, predendog, inst, liml=true, clustid=df.industry)</code></pre></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../OLSexamples/">« OLS examples</a><a class="docs-footer-nextpage" href="../exported/">Public functions and types »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.27.25 on <span class="colophon-date" title="Wednesday 17 April 2024 22:06">Wednesday 17 April 2024</span>. Using Julia version 1.8.5.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>OLS examples · WildBootTests.jl</title><script data-outdated-warner src="../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href="../">WildBootTests.jl</a></span></div><form class="docs-search" action="../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../">Overview</a></li><li class="is-active"><a class="tocitem" href>OLS examples</a><ul class="internal"><li><a class="tocitem" href="#Basic-OLS-example"><span>Basic OLS example</span></a></li><li><a class="tocitem" href="#Further-examples"><span>Further examples</span></a></li></ul></li><li><a class="tocitem" href="../IVexamples/">IV/2SLS examples</a></li><li><a class="tocitem" href="../exported/">Public functions and types</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>OLS examples</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>OLS examples</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/droodman/WildBootTests.jl/blob/master/docs/src/OLSexamples.md" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h2 id="Basic-OLS-example"><a class="docs-heading-anchor" href="#Basic-OLS-example">Basic OLS example</a><a id="Basic-OLS-example-1"></a><a class="docs-heading-anchor-permalink" href="#Basic-OLS-example" title="Permalink"></a></h2><pre><code class="nohighlight hljs">julia> using WildBootTests, CSV, DataFrames, StatsModels, GLM, Plots | ||
|
||
julia> d = download("https://raw.github.com/vincentarelbundock/Rdatasets/master/csv/sandwich/PetersenCL.csv"); | ||
|
||
julia> df = CSV.read(d, DataFrame); | ||
|
||
julia> f = @formula(y ~ 1 + x); # state OLS model | ||
|
||
julia> f = apply_schema(f, schema(f, df)); # link model to data | ||
|
||
julia> lm(f, df) # run OLS for illustration; not needed for following lines | ||
StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}}}}, Matrix{Float64}} | ||
|
||
y ~ 1 + x | ||
|
||
Coefficients: | ||
───────────────────────────────────────────────────────────────────────── | ||
Coef. Std. Error t Pr(>|t|) Lower 95% Upper 95% | ||
───────────────────────────────────────────────────────────────────────── | ||
(Intercept) 0.0296797 0.0283593 1.05 0.2954 -0.025917 0.0852764 | ||
x 1.03483 0.0285833 36.20 <1e-99 0.978798 1.09087 | ||
───────────────────────────────────────────────────────────────────────── | ||
|
||
julia> resp, predexog = modelcols(f, df); # extract response & (exogenous) predictor variables | ||
|
||
julia> clustid = df.firm; # extract clustering variable | ||
|
||
julia> R = [0 1]; r = [1]; # put null that coefficient on x = 1 in Rβ̂ = r form, where β̂ is parameter vector | ||
|
||
julia> test = wildboottest(R, r; resp=resp, predexog=predexog, clustid=clustid) | ||
WildBootTests.BootTestResult{Float32} | ||
|
||
p = 0.492 | ||
ci = Float32[0.93461335 1.1347668] | ||
|
||
julia> test = wildboottest(R, r; resp, predexog, clustid); # same, using Julia syntactic sugar | ||
|
||
julia> p(test) # programmatically extract p value | ||
0.49459493f0 | ||
|
||
julia> ci(test) # programmatically extract confidence interval | ||
1×2 Matrix{Float32}: | ||
0.934961 1.13469 | ||
|
||
julia> plot(plotpoints(test)...) # plot confidence curve</code></pre><h2 id="Further-examples"><a class="docs-heading-anchor" href="#Further-examples">Further examples</a><a id="Further-examples-1"></a><a class="docs-heading-anchor-permalink" href="#Further-examples" title="Permalink"></a></h2><pre><code class="nohighlight hljs">using WildBootTests, CSV, DataFrames, StatsModels, GLM, Plots | ||
|
||
# use Webb instead of Rademacher weights, 99,999 bootstrap replications instead of 999 | ||
wildboottest(R, r; resp, predexog, clustid, reps=99999, auxwttype=:webb) | ||
|
||
# jackknife the bootstrap data-generating process to reduce distortion from outliers | ||
wildboottest(Float64, R, r; resp, predexog, clustid, jk=true) | ||
|
||
# use guaranteed-stable random number generator for exact replicability | ||
using StableRNGs | ||
wildboottest(R, r; resp, predexog, clustid, rng=StableRNG(23948572)) | ||
|
||
# test that coefficient on intercept = 0 and coefficient on x = 1; plot confidence surface | ||
test = wildboottest([1 0; 0 1], [0;1]; resp, predexog, clustid, reps=9999) | ||
plot(plotpoints(test).X..., plotpoints(test).p, st=:contourf) | ||
|
||
# multiway-cluster errors by firm and year; bootstrap by firm | ||
wildboottest(R, r; resp, predexog, clustid=Matrix(df[:,[:firm, :year]]), nerrclustvar=2, nbootclustvar=1) | ||
|
||
# same but bootstrap by year | ||
wildboottest(R, r; resp, predexog, clustid=Matrix(df[:,[:year, :firm]]), nerrclustvar=2, nbootclustvar=1) | ||
|
||
# same but bootstrap by year-firm pair | ||
wildboottest(R, r; resp, predexog, clustid=Matrix(df[:,[:year, :firm]]), nerrclustvar=2, nbootclustvar=2) | ||
|
||
# Rao/score test with multiway clustering of errors but no bootstrap | ||
wildboottest(R, r; resp, predexog, predendog, inst, Matrix(df[:,[:year, :firm]]), reps=0) | ||
|
||
# Same but Wald test: i.e., conventional, multiway clustered errors | ||
wildboottest(R, r; resp, predexog, predendog, inst, clustid=Matrix(df[:,[:year, :firm]]), reps=0, imposenull=false) | ||
|
||
# add year fixed effects to model; cluster by firm | ||
wildboottest(R, r; resp, predexog, feid=df.year, clustid=df.firm) | ||
|
||
# test hypotheses, while imposing model constraint that constant term = 0.2 | ||
R1 = [1 0]; r1 = [.2] | ||
wildboottest(R, r; R1, r1, resp, predexog, clustid=df.firm)</code></pre></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Overview</a><a class="docs-footer-nextpage" href="../IVexamples/">IV/2SLS examples »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.27.25 on <span class="colophon-date" title="Wednesday 17 April 2024 22:06">Wednesday 17 April 2024</span>. Using Julia version 1.8.5.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
Oops, something went wrong.