Comments (2)
Hi, I second this, it would be very convenient to have a function to plot the trends of the treated unit(s) and of the synthethic control of single_augsynth()
and multisynth()
.
@Germancampos regarding your second point, plot
returns a ggplot object, meaning that you can then customize it as you want with other ggplot2
functions (and extensions). Here's an example coming from the multisynth
vignette:
library(magrittr)
library(dplyr)
library(augsynth)
library(ggplot2)
data <- read.csv("https://dataverse.harvard.edu/api/access/datafile/:persistentId?persistentId=doi:10.7910/DVN/WGWMAV/3UHTLP", sep="\t")
data %>%
filter(!State %in% c("DC", "WI"),
year >= 1959, year <= 1997) %>%
mutate(YearCBrequired = ifelse(is.na(YearCBrequired),
Inf, YearCBrequired),
cbr = 1 * (year >= YearCBrequired)) -> analysis_df
ppool_syn <- multisynth(lnppexpend ~ cbr, State, year,
nu = 0.5, analysis_df)
plot(summary(ppool_syn), levels = "Average", label = FALSE) +
theme_dark() +
geom_line(color = "red") +
geom_point(color = "red") +
labs(title = "This is my plot")
Note however that the red line and points are simply put above the default black ones. This means that adding something like linetype = "dashed"
in geom_line()
will show parts of the original line (see below). Since these lines and points are hardcoded in plot
, I don't think it is possible to remove them.
from augsynth.
@etiennebacher that's right. I think you could remove plot elements from the ggplot object and add new ones, but at that point, you should make your own plot directly from the results.
@Germancampos for your first question about plotting on the outcome scale, you can do this by accessing the effect estimates directly. After running the summary
function for either single_augsynth
or multisynth
, you can take the att
element of the summary object to get the estimates. E.g. for the example above summary(ppool_syn)$att
will give a data frame of all the effect estimates. You can then merge this in with the actual data to graph the outcome series and it's synthetic control.
Here's how that looks for the kansas
dataset and single_augsynth
:
library(tidyverse)
library(augsynth)
data(kansas)
# fit augsynth and get effect estimates
syn <- augsynth(lngdpcapita ~ treated, fips, year_qtr, kansas)
att <- summary(syn)$att
# combine with data
kansas %>%
filter(state == "Kansas") %>%
select(year_qtr, lngdpcapita) %>%
inner_join(att, by = c("year_qtr"="Time")) %>%
ggplot(aes(x = year_qtr)) +
geom_line(aes(y = lngdpcapita)) +
geom_line(aes(y = lngdpcapita + Estimate), lty = 2, color = "red")
That'll give you something like this
That could be added in the future. My only caution is that plotting the outcomes directly like this makes it more difficult to see how well the synthetic control is fitting the pre-treatment periods, since it's all washed out in the overall trend in gdp.
from augsynth.
Related Issues (20)
- scm = F broken in multisynth
- Stata package
- how to interpret the results obtain with multisynth HOT 2
- Confidence interval that includes the value of zero HOT 1
- No confidence intervals of average ATT for conformal inference type
- Adding auxiliary covariates causes fatal error HOT 1
- Examples of how to use `cov_agg`?
- Codes for result plots and tables?
- Weighted ATT HOT 1
- 'list' object cannot be coerced to type 'double'
- Changing the setting alpha does not alter the confidence intervals when using multisynth HOT 1
- GSYN model not working HOT 1
- Problem with installation since Apr 14th 2023
- Conformal Inference procedure p-value potential issue HOT 1
- Examples for SCM with staggered adoption HOT 1
- Very ram consuming HOT 3
- Base year of Event time Plot
- Standard Errors
- about subsample augsynth
- Cannot recognize data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from augsynth.