Skip to content

Instantly share code, notes, and snippets.

@acoppock
Created February 25, 2019 17:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acoppock/91c94fa6433a05ee54c2100dbfd889ca to your computer and use it in GitHub Desktop.
Save acoppock/91c94fa6433a05ee54c2100dbfd889ca to your computer and use it in GitHub Desktop.
stata_challenge
# 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