Skip to content

Commit 0ae9a74

Browse files
committed
updates
1 parent c9332a5 commit 0ae9a74

File tree

299 files changed

+2745
-1243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

299 files changed

+2745
-1243
lines changed

.Rprofile

Whitespace-only changes.

02-ch2.Rmd

+3-3
Original file line numberDiff line numberDiff line change
@@ -1070,9 +1070,9 @@ cat('
10701070
<p>
10711071
The sample average $\\overline{Y}$ converges in probability to $\\mu_Y$: $\\overline{Y}$ is *consistent* for $\\mu_Y$ if the probability that $\\overline{Y}$ is in the range $(\\mu_Y - \\epsilon)$ to $(\\mu_Y + \\epsilon)$ becomes arbitrary close to $1$ as $n$ increases for any constant $\\epsilon > 0$. We write this as
10721072
1073-
$$ \\overline{Y} \\xrightarrow[]{p} \\mu_Y. $$
1073+
$$ P(\\mu_Y-\\epsilon \\leq \\overline{Y} \\leq \\mu_Y + \\epsilon) \\rightarrow 1, \\, \\epsilon > 0 \\text{ as } n\\rightarrow\\infty. $$
10741074
1075-
Consider the independently and identically distributed random variables $Y_i, i=1,\\dots,n$ with expectation $E(Y_i)=\\mu_Y$ and variance $\\text{Var}(Y_i)=\\sigma^2_Y$. Under the condition that $\\sigma^2_Y< \\infty$, that is, large outliers are unlikely, the law of large numbers states
1075+
Consider the independently and identically distributed random variables $Y_i, i=1,\\dots,n$ with expectation $E(Y_i)=\\mu_Y$ and variance $\\text{Var}(Y_i)=\\sigma^2_Y$. Under the condition that $\\sigma^2_Y< \\infty$, that is, large outliers are unlikely, the law of large numbers thus states that
10761076
10771077
$$ \\overline{Y} \\xrightarrow[]{p} \\mu_Y. $$
10781078
@@ -1086,7 +1086,7 @@ The following application simulates a large number of coin tosses (you may set t
10861086
cat('\\begin{keyconcepts}[Convergence in Probability\\comma Consistency and the Law of Large Numbers]{2.6}
10871087
The sample average $\\overline{Y}$ converges in probability to $\\mu_Y$: $\\overline{Y}$ is \\textit{consistent} for $\\mu_Y$ if the probability that $\\overline{Y}$ is in the range $(\\mu_Y - \\epsilon)$ to $(\\mu_Y + \\epsilon)$ becomes arbitrary close to $1$ as $n$ increases for any constant $\\epsilon > 0$. We write this as
10881088
1089-
$$ \\overline{Y} \\xrightarrow[]{p} \\mu_Y. $$
1089+
$$ P(\\mu_Y-\\epsilon \\leq \\overline{Y} \\leq \\mu_Y + \\epsilon) \\rightarrow 1, \\, \\epsilon > 0 \\text{ as } n\\rightarrow\\infty. $$
10901090
10911091
Consider the independently and identically distributed random variables $Y_i, i=1,\\dots,n$ with expectation $E(Y_i)=\\mu_Y$ and variance $\\text{Var}(Y_i)=\\sigma^2_Y$. Under the condition that $\\sigma^2_Y< \\infty$, that is, large outliers are unlikely, the law of large numbers states
10921092

10-ch10.Rmd

+59
Original file line numberDiff line numberDiff line change
@@ -651,4 +651,63 @@ We have not found evidence that severe punishments and increasing the minimum dr
651651

652652
A powerful method that can be used if common panel regression approaches fail is instrumental variables regression. We will return to this concept in Chapter \@ref(ivr).
653653

654+
## Exercises
654655

656+
```{r, echo=FALSE, results='asis'}
657+
if (my_output=="html"){
658+
cat('
659+
For the course of this section, you will work with <tt>Guns</tt>, a balanced panel containing observations on criminal and demographic variables for all US states and the years 1977-1999. The data set comes with the package <tt>AER</tt> which is already installed for the interactive R exercises below.
660+
661+
<div class = "DCexercise">
662+
663+
#### 1. The Guns Data Set {-}
664+
665+
**Instructions:**
666+
667+
+ Load both the package and the data set.
668+
669+
+ Get yourself an overview over the data set using the <tt>summary()</tt> function. Use <tt>?Guns</tt> for detailed information on the variables.
670+
671+
+ Verify that <tt>Guns</tt> is a balanced panel. Do so by extracting the number of years and states from the data set and assign them to the predefined variables <tt>years</tt> and <tt>states</tt>, respectively. Afterwards use these variables for a logical comparison: check that the panel is balanced
672+
673+
<iframe src="DCL/ex10_1.html" frameborder="0" scrolling="no" style="width:100%;height:340px"></iframe>
674+
675+
**Hints:**
676+
677+
+ Use <tt>library()</tt> and <tt>data()</tt> to attach the package and load the data set, respectively.
678+
+ Use <tt>summary()</tt> to obtain a comprehensive overview of the dataset.
679+
+ In order to be a balanced panel the number of entities times the number of years has to be equal to the total number of observations in the dataset. The basic functions <tt>levels()</tt>, <tt>length()</tt> and <tt>nrow()</tt> may be useful here to accomplish this task.
680+
681+
</div>')
682+
} else {
683+
cat('\\begin{center}\\textit{This interactive part of URFITE is only available in the HTML version.}\\end{center}')
684+
}
685+
```
686+
687+
```{r, echo=FALSE, results='asis'}
688+
if (my_output=="html") {
689+
cat('
690+
<div class = "DCexercise">
691+
692+
#### 2. Strict or Loose? Gun Laws and the Effect on Crime I {-}
693+
694+
There is a controversial debate on whether and to what extent the right to carry a gun influences crime. Proponents of so-called "Carrying a Concealed Weapon" (CCW) laws argue that the deterrent effect of guns prevents crime, whereas opponents argue that ... In the following exercises you will empirically investigate this topic.
695+
696+
To begin with consider the following estimated model $$\\widehat{{\\log(violent_i)}} = 6.135 - 0.443 \\times law_i$$, where <tt>violent</tt> and <tt>law</tt> denote the violent crime rate (incidents per $100000$ citizens) and a binary variable indicating the implementation of a CCW law (1 = yes, 0 = no), respectively.
697+
698+
The packages <tt>AER</tt> and <tt>plm</tt> have been loaded.
699+
700+
**Instructions:**
701+
702+
+ Is the proposed model a "good" model? In particular, are there variables that vary across states?
703+
704+
+ Print a summary of the model reporting robust standard errors. Analyze thr results.
705+
706+
<iframe src="DCL/ex10_2.html" frameborder="0" scrolling="no" style="width:100%;height:340px"></iframe>
707+
708+
**Hints:**
709+
710+
+ As usual you can use <tt>coeftest()</tt> in conjunction with appropriate arguments to obtain a summary output with robust standard errors.
711+
</div>')
712+
}
713+
```

DCL/ex10_1.html

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset='utf-8'/>
5+
<script async='async' src='https://cdn.datacamp.com/dcl-react-dev.js.gz'></script>
6+
<style>
7+
.DCexercise .datacamp-exercise {
8+
border: 2px solid #3D678D;
9+
border-radius: 10px 10px 10px 10px !important;
10+
}
11+
12+
*[class*="lm_"], .ace_gutter, textarea[class*="ace_"], .ace_scroller {
13+
background-color: #F0EFF0 !important;
14+
}
15+
16+
div[class*="Editor-module__editor"], div[class*="dcl__Footer"] {
17+
background-color: #3D678D !important;
18+
}
19+
20+
*[class*="lm_"] {
21+
border-radius: 10px 10px 0px 0px !important;
22+
}
23+
24+
div[class*="dcl__Footer"] {
25+
border-radius: 0px 0px 10px 10px !important;
26+
}
27+
28+
.lm_content {
29+
border-radius: 0px !important;
30+
}
31+
32+
.lm_splitter {
33+
background-color: #3D678D !important;
34+
width: 3px !important;
35+
}
36+
37+
.lm_drag_handle {
38+
background: transparent !important;
39+
}
40+
41+
div[class*="dcl__index-module"] {
42+
outline-color: transparent !important;
43+
border-radius: 10px !important;
44+
}
45+
46+
button[class*="secondary-light"] {
47+
background-color: #FF0000;
48+
}
49+
</style>
50+
</head>
51+
<body>
52+
53+
<div data-datacamp-exercise data-lang="r">
54+
55+
<code data-type="pre-exercise-code">
56+
</code>
57+
58+
<code data-type="sample-code">
59+
# attach the package and load the data set
60+
61+
62+
63+
# obtain an overview over the data set
64+
65+
66+
# verify that Guns is a balanced panel
67+
years <-
68+
states <-
69+
70+
71+
</code>
72+
73+
<code data-type="solution">
74+
# attach the package and load the data set
75+
library(AER)
76+
data("Guns")
77+
78+
# obtain an overview over the data set
79+
summary(Guns)
80+
81+
# verify that Guns is a balanced panel
82+
years <- length(levels(Guns$year))
83+
states <- length(levels(Guns$state))
84+
years*states == nrow(Guns)
85+
86+
</code>
87+
88+
<code data-type="sct">
89+
ex %>% check_library("AER")
90+
test_function("data")
91+
test_or({
92+
ex() %>% check_function("summary") %>% check_result() %>% check_equal()
93+
},{
94+
f <- ex() %>% override_solution("str(Guns)")
95+
f %>% check_function("str") %>% check_result() %>% check_equal()
96+
})
97+
ex() %>% check_object("years") %>% check_equal()
98+
ex() %>% check_object("states") %>% check_equal()
99+
ex() %>% check_function("nrow") %>% check_arg("x") %>% check_equal()
100+
test_or({
101+
test_student_typed("years*states == nrow(Guns)")
102+
},{
103+
test_student_typed("states*years == nrow(Guns)")
104+
},{
105+
test_student_typed("nrow(Guns) == years*states")
106+
},{
107+
test_student_typed("nrow(Guns) == states*years")
108+
})
109+
success_msg("Correct! Overall there are 51 states (entities) over 23 years whose product coincides with the number of total observations in the dataset.")
110+
</code>
111+
112+
</div>
113+
114+
</body>
115+
</html>

DCL/ex10_2.html

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset='utf-8'/>
5+
<script async='async' src='https://cdn.datacamp.com/dcl-react-dev.js.gz'></script>
6+
<style>
7+
.DCexercise .datacamp-exercise {
8+
border: 2px solid #3D678D;
9+
border-radius: 10px 10px 10px 10px !important;
10+
}
11+
12+
*[class*="lm_"], .ace_gutter, textarea[class*="ace_"], .ace_scroller {
13+
background-color: #F0EFF0 !important;
14+
}
15+
16+
div[class*="Editor-module__editor"], div[class*="dcl__Footer"] {
17+
background-color: #3D678D !important;
18+
}
19+
20+
*[class*="lm_"] {
21+
border-radius: 10px 10px 0px 0px !important;
22+
}
23+
24+
div[class*="dcl__Footer"] {
25+
border-radius: 0px 0px 10px 10px !important;
26+
}
27+
28+
.lm_content {
29+
border-radius: 0px !important;
30+
}
31+
32+
.lm_splitter {
33+
background-color: #3D678D !important;
34+
width: 3px !important;
35+
}
36+
37+
.lm_drag_handle {
38+
background: transparent !important;
39+
}
40+
41+
div[class*="dcl__index-module"] {
42+
outline-color: transparent !important;
43+
border-radius: 10px !important;
44+
}
45+
46+
button[class*="secondary-light"] {
47+
background-color: #FF0000;
48+
}
49+
</style>
50+
</head>
51+
<body>
52+
53+
54+
<div data-datacamp-exercise data-lang="r">
55+
56+
<code data-type="pre-exercise-code">
57+
library(AER)
58+
</code>
59+
60+
<code data-type="sample-code">
61+
# estimate a model with fixed state effects
62+
model_fe <-
63+
64+
# print a summary using robust standard errors
65+
66+
67+
</code>
68+
69+
<code data-type="solution">
70+
# estimate a model with fixed state effects
71+
model_fe <- plm(log(violent) ~ law, data = Guns, index = c("state", "year"), model = "within")
72+
73+
# print a summary using robust standard errors
74+
coeftest(model_fe, vcov. = vcovHC, type = "HC1")
75+
76+
</code>
77+
78+
<code data-type="sct">
79+
success_msg("Correct! The proposed model has two severe shortcomings: First the model does not account for variables that vary across the entities. The coefficient is surprisingly large in magnitude which is likely due to omitted variable bias.")
80+
</code>
81+
82+
</div>
83+
84+
</body>
85+
</html>
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

docs/1-1-a-very-short-introduction-to-r-and-rstudio.html

+6-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<meta name="author" content="Christoph Hanck, Martin Arnold, Alexander Gerber and Martin Schmelzer">
2626

2727

28-
<meta name="date" content="2018-10-12">
28+
<meta name="date" content="2018-10-30">
2929

3030
<meta name="viewport" content="width=device-width, initial-scale=1">
3131
<meta name="apple-mobile-web-app-capable" content="yes">
@@ -58,15 +58,9 @@
5858

5959
<link href="https://fonts.googleapis.com/css?family=PT+Sans|Pacifico|Source+Sans+Pro" rel="stylesheet">
6060

61-
<!-- function to adjust height of iframes automatically depending on content loaded -->
62-
63-
<script>
64-
function resizeIframe(obj) {
65-
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
66-
}
67-
</script>
68-
6961
<script src="js/hideOutput.js"></script>
62+
63+
<!-- Mathjax -->
7064
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/default.js"></script>
7165

7266
<script type="text/x-mathjax-config">
@@ -277,6 +271,7 @@
277271
<li class="chapter" data-level="10.4" data-path="10-4-regression-with-time-fixed-effects.html"><a href="10-4-regression-with-time-fixed-effects.html"><i class="fa fa-check"></i><b>10.4</b> Regression with Time Fixed Effects</a></li>
278272
<li class="chapter" data-level="10.5" data-path="10-5-tferaaseffer.html"><a href="10-5-tferaaseffer.html"><i class="fa fa-check"></i><b>10.5</b> The Fixed Effects Regression Assumptions and Standard Errors for Fixed Effects Regression</a></li>
279273
<li class="chapter" data-level="10.6" data-path="10-6-drunk-driving-laws-and-traffic-deaths.html"><a href="10-6-drunk-driving-laws-and-traffic-deaths.html"><i class="fa fa-check"></i><b>10.6</b> Drunk Driving Laws and Traffic Deaths</a></li>
274+
<li class="chapter" data-level="10.7" data-path="10-7-exercises-8.html"><a href="10-7-exercises-8.html"><i class="fa fa-check"></i><b>10.7</b> Exercises</a></li>
280275
</ul></li>
281276
<li class="chapter" data-level="11" data-path="11-rwabdv.html"><a href="11-rwabdv.html"><i class="fa fa-check"></i><b>11</b> Regression with a Binary Dependent Variable</a><ul>
282277
<li class="chapter" data-level="11.1" data-path="11-1-binary-dependent-variables-and-the-linear-probability-model.html"><a href="11-1-binary-dependent-variables-and-the-linear-probability-model.html"><i class="fa fa-check"></i><b>11.1</b> Binary Dependent Variables and the Linear Probability Model</a></li>
@@ -286,15 +281,15 @@
286281
</ul></li>
287282
<li class="chapter" data-level="11.3" data-path="11-3-estimation-and-inference-in-the-logit-and-probit-models.html"><a href="11-3-estimation-and-inference-in-the-logit-and-probit-models.html"><i class="fa fa-check"></i><b>11.3</b> Estimation and Inference in the Logit and Probit Models</a></li>
288283
<li class="chapter" data-level="11.4" data-path="11-4-application-to-the-boston-hmda-data.html"><a href="11-4-application-to-the-boston-hmda-data.html"><i class="fa fa-check"></i><b>11.4</b> Application to the Boston HMDA Data</a></li>
289-
<li class="chapter" data-level="11.5" data-path="11-5-exercises-8.html"><a href="11-5-exercises-8.html"><i class="fa fa-check"></i><b>11.5</b> Exercises</a></li>
284+
<li class="chapter" data-level="11.5" data-path="11-5-exercises-9.html"><a href="11-5-exercises-9.html"><i class="fa fa-check"></i><b>11.5</b> Exercises</a></li>
290285
</ul></li>
291286
<li class="chapter" data-level="12" data-path="12-ivr.html"><a href="12-ivr.html"><i class="fa fa-check"></i><b>12</b> Instrumental Variables Regression</a><ul>
292287
<li class="chapter" data-level="12.1" data-path="12-1-TIVEWASRAASI.html"><a href="12-1-TIVEWASRAASI.html"><i class="fa fa-check"></i><b>12.1</b> The IV Estimator with a Single Regressor and a Single Instrument</a></li>
293288
<li class="chapter" data-level="12.2" data-path="12-2-TGIVRM.html"><a href="12-2-TGIVRM.html"><i class="fa fa-check"></i><b>12.2</b> The General IV Regression Model</a></li>
294289
<li class="chapter" data-level="12.3" data-path="12-3-civ.html"><a href="12-3-civ.html"><i class="fa fa-check"></i><b>12.3</b> Checking Instrument Validity</a></li>
295290
<li class="chapter" data-level="12.4" data-path="12-4-attdfc.html"><a href="12-4-attdfc.html"><i class="fa fa-check"></i><b>12.4</b> Application to the Demand for Cigarettes</a></li>
296291
<li class="chapter" data-level="12.5" data-path="12-5-where-do-valid-instruments-come-from.html"><a href="12-5-where-do-valid-instruments-come-from.html"><i class="fa fa-check"></i><b>12.5</b> Where Do Valid Instruments Come From?</a></li>
297-
<li class="chapter" data-level="12.6" data-path="12-6-exercises-9.html"><a href="12-6-exercises-9.html"><i class="fa fa-check"></i><b>12.6</b> Exercises</a></li>
292+
<li class="chapter" data-level="12.6" data-path="12-6-exercises-10.html"><a href="12-6-exercises-10.html"><i class="fa fa-check"></i><b>12.6</b> Exercises</a></li>
298293
</ul></li>
299294
<li class="chapter" data-level="13" data-path="13-eaqe.html"><a href="13-eaqe.html"><i class="fa fa-check"></i><b>13</b> Experiments and Quasi-Experiments</a><ul>
300295
<li class="chapter" data-level="13.1" data-path="13-1-potential-outcomes-causal-effects-and-idealized-experiments.html"><a href="13-1-potential-outcomes-causal-effects-and-idealized-experiments.html"><i class="fa fa-check"></i><b>13.1</b> Potential Outcomes, Causal Effects and Idealized Experiments</a></li>

0 commit comments

Comments
 (0)