Skip to content

Commit

Permalink
Run under R 4.4.1 and StataNow 18.5
Browse files Browse the repository at this point in the history
  • Loading branch information
remlapmot committed Jun 16, 2024
1 parent 359f1cd commit 263f220
Show file tree
Hide file tree
Showing 51 changed files with 5,645 additions and 4,709 deletions.
Binary file modified data/fig1.dta
Binary file not shown.
Binary file modified data/fig2.dta
Binary file not shown.
Binary file modified data/fig3.dta
Binary file not shown.
Binary file modified data/nhefs-formatted.dta
Binary file not shown.
Binary file modified data/nhefs-highprice.dta
Binary file not shown.
Binary file modified data/nhefs-ps.dta
Binary file not shown.
Binary file modified data/nhefs-wcens.dta
Binary file not shown.
Binary file modified data/nhefs_std.dta
Binary file not shown.
Binary file modified data/nhefs_std1.dta
Binary file not shown.
Binary file modified data/nhefs_std2.dta
Binary file not shown.
Binary file modified data/nhefs_surv.dta
Binary file not shown.
Binary file modified data/observe.mmat
Binary file not shown.
36 changes: 30 additions & 6 deletions docs/11-why-model-r.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- Data from Figures 11.1 and 11.2


```r
``` r
A <- c(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0)
Y <- c(200, 150, 220, 110, 50, 180, 90, 170, 170, 30,
70, 110, 80, 50, 10, 20)
Expand All @@ -20,13 +20,19 @@ plot(A, Y)

<img src="11-why-model-r_files/figure-epub3/unnamed-chunk-1-1.png" width="85%" style="display: block; margin: auto;" />

```r
``` r
summary(Y[A == 0])
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 10.0 27.5 60.0 67.5 87.5 170.0
```

``` r
summary(Y[A == 1])
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 50.0 105.0 160.0 146.2 185.0 220.0
```

``` r

A2 <- c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4)
Y2 <- c(110, 80, 50, 40, 170, 30, 70, 50, 110, 50, 180,
Expand All @@ -37,16 +43,25 @@ plot(A2, Y2)

<img src="11-why-model-r_files/figure-epub3/unnamed-chunk-1-2.png" width="85%" style="display: block; margin: auto;" />

```r
``` r
summary(Y2[A2 == 1])
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 40.0 47.5 65.0 70.0 87.5 110.0
```

``` r
summary(Y2[A2 == 2])
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 30 45 60 80 95 170
```

``` r
summary(Y2[A2 == 3])
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 50.0 95.0 120.0 117.5 142.5 180.0
```

``` r
summary(Y2[A2 == 4])
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 150.0 187.5 205.0 195.0 212.5 220.0
Expand All @@ -59,7 +74,7 @@ summary(Y2[A2 == 4])
- Data from Figures 11.3 and 11.1


```r
``` r
A3 <-
c(3, 11, 17, 23, 29, 37, 41, 53, 67, 79, 83, 97, 60, 71, 15, 45)
Y3 <-
Expand All @@ -71,7 +86,7 @@ plot(Y3 ~ A3)

<img src="11-why-model-r_files/figure-epub3/unnamed-chunk-2-1.png" width="85%" style="display: block; margin: auto;" />

```r
``` r

summary(glm(Y3 ~ A3))
#>
Expand All @@ -92,9 +107,15 @@ summary(glm(Y3 ~ A3))
#> AIC: 170.43
#>
#> Number of Fisher Scoring iterations: 2
```

``` r
predict(glm(Y3 ~ A3), data.frame(A3 = 90))
#> 1
#> 216.89
```

``` r

summary(glm(Y ~ A))
#>
Expand Down Expand Up @@ -123,7 +144,7 @@ summary(glm(Y ~ A))
- Data from Figure 11.3


```r
``` r
Asq <- A3 * A3

mod3 <- glm(Y3 ~ A3 + Asq)
Expand All @@ -147,6 +168,9 @@ summary(mod3)
#> AIC: 170.39
#>
#> Number of Fisher Scoring iterations: 2
```

``` r
predict(mod3, data.frame(cbind(A3 = 90, Asq = 8100)))
#> 1
#> 197.1269
Expand Down
16 changes: 8 additions & 8 deletions docs/11-why-model-stata.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# 11. Why model: Stata{-}


```r
``` r
library(Statamarkdown)
```


```stata
``` stata
do dependency
```

Expand All @@ -35,7 +35,7 @@ For errors contact: ejmurray@bu.edu
- Sample averages by treatment level


```stata
``` stata
clear
**Figure 11.1**
Expand Down Expand Up @@ -112,7 +112,7 @@ bysort A: sum Y
<img src="figs/stata-fig-11-1.png" width="85%" style="display: block; margin: auto;" />


```stata
``` stata
*Clear the workspace to be able to use a new dataset*
clear
Expand Down Expand Up @@ -200,7 +200,7 @@ bysort A: sum Y
<img src="figs/stata-fig-11-2.png" width="85%" style="display: block; margin: auto;" />


```stata
``` stata
clear
**Figure 11.3**
Expand Down Expand Up @@ -258,7 +258,7 @@ qui gr export figs/stata-fig-11-3.png, replace
- Creates Figure 11.4, parameter estimates with 95% confidence intervals from Section 11.2, and parameter estimates with 95% confidence intervals from Section 11.3


```stata
``` stata
**Section 11.2: parametric estimators**
*Reload data
use ./data/fig3, clear
Expand Down Expand Up @@ -297,7 +297,7 @@ qui gr export figs/stata-fig-11-4.png, replace
<img src="figs/stata-fig-11-4.png" width="85%" style="display: block; margin: auto;" />


```stata
``` stata
**Section 11.3: non-parametric estimation*
* Reload the data
use ./data/fig1, clear
Expand Down Expand Up @@ -325,7 +325,7 @@ di 67.50 + 78.75
- Creates Figure 11.5 and Parameter estimates for Section 11.4


```stata
``` stata
* Reload the data
use ./data/fig3, clear
Expand Down
Loading

0 comments on commit 263f220

Please sign in to comment.