Created
February 25, 2019 17:29
-
-
Save acoppock/91c94fa6433a05ee54c2100dbfd889ca to your computer and use it in GitHub Desktop.
stata_challenge
This file contains hidden or 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
# How to make this plot in Stata? | |
library(tidyverse) | |
library(estimatr) | |
library(randomizr) | |
# make some fake data | |
dat <- tibble(Y = rnorm(100), | |
Z = complete_ra(100, conditions = c("Control", "Treament"))) | |
# obtain group means and confidence intervals | |
summary_df <- | |
dat %>% group_by(Z) %>% | |
do(tidy(lm_robust(Y ~ 1, data = .))) %>% | |
mutate(Y = estimate) | |
# plot | |
ggplot(summary_df, aes(Z, Y)) + | |
geom_point(size = 3) + | |
geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0) + | |
geom_point(data = dat, position = position_jitter(width = 0.1), alpha = 0.3) + | |
theme_bw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment