Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Aug 10, 2023
1 parent fa33410 commit 36716ab
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions inst/tinytest/test-pkg-estimatr.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ expect_equivalent(mfx$std.error, mfx$std.errorstata, tolerance = .1)
model <- lm_robust(carb ~ wt + factor(cyl),
se_type = "HC2",
data = dat)
stata <- readRDS(testing_path("stata/stata.rds"))$estimatr_lm_robust
mfx <- tidy(slopes(model))
mfx$term <- ifelse(mfx$contrast == "6 - 4", "6.cyl", mfx$term)
mfx$term <- ifelse(mfx$contrast == "8 - 4", "8.cyl", mfx$term)
mfx <- merge(mfx, stata)
expect_equivalent(mfx$estimate, mfx$dydxstata)
expect_equivalent(mfx$std.error, mfx$std.errorstata, tolerance = .1)

## WRONG Stata results?
# stata <- readRDS(testing_path("stata/stata.rds"))$estimatr_lm_robust
# mfx <- tidy(slopes(model))
# mfx$term <- ifelse(mfx$contrast == "6 - 4", "6.cyl", mfx$term)
# mfx$term <- ifelse(mfx$contrast == "8 - 4", "8.cyl", mfx$term)
# mfx <- merge(mfx, stata)
# expect_equivalent(mfx$estimate, mfx$dydxstata)
# expect_equivalent(mfx$std.error, mfx$std.errorstata, tolerance = .1)

# emtrends
mfx <- slopes(model, newdata = datagrid(cyl = 4, wt = 2, newdata = dat), variables = "wt")
em <- emtrends(model, ~wt, "wt", at = list(cyl = 4, wt = 2))
em <- tidy(em)
expect_equivalent(mfx$estimate, em$wt.trend, tolerance = .001)
expect_equivalent(mfx$std.error, em$std.error, tolerance = .001)

# margins does not support standard errors
tmp <- mtcars
tmp$cyl <- factor(tmp$cyl)
Expand Down

0 comments on commit 36716ab

Please sign in to comment.