Intro to sreg

Here, we provide the empirical application example using the data from (Chong et al., 2016), who studied the effect of iron deficiency anemia on school-age children's educational attainment and cognitive ability in Peru. The example replicates the empirical illustration from (Bugni et al., 2019). For replication purposes, the data is included in the package and can be accessed by running data("AEJapp").

library(sreg)
library(haven)
library(dplyr)

We can upload the AEJapp dataset to the R session via data():

data(AEJapp)
data <- AEJapp

It is pretty straightforward to prepare the data to fit the package syntax using dplyr:

Y <- data$gradesq34
D <- data$treatment
S <- data$class_level
data.clean <- data.frame(Y, D, S)
data.clean <- data.clean %>%
  mutate(D = ifelse(D == 3, 0, D))
Y <- data.clean$Y
D <- data.clean$D
S <- data.clean$S
head(data.clean)

We can take a look at the frequency table of D and S:

table(D = data.clean$D, S = data.clean$S)

Now, it is straightforward to replicate the results from (Bugni et al, 2019) using sreg():

result <- sreg::sreg(Y = Y, S = S, D = D)
print(result)

Besides that, sreg allows adding linear adjustments (covariates) to the estimation procedure:

pills <- data$pills_taken
age <- data$age_months
data.clean <- data.frame(Y, D, S, pills, age)
data.clean <- data.clean %>%
  mutate(D = ifelse(D == 3, 0, D))
Y <- data.clean$Y
D <- data.clean$D
S <- data.clean$S
X <- data.frame("pills" = data.clean$pills, "age" = data.clean$age)
result <- sreg::sreg(Y, S, D, G.id = NULL, X = X)
print(result)


Try the sreg package in your browser

Any scripts or data that you put into this service are public.

sreg documentation built on Aug. 25, 2025, 5:14 p.m.