diff --git a/DESCRIPTION b/DESCRIPTION index 4067031..1536ea9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,6 +21,9 @@ Imports: ggplot2 (>= 3.4.2), ggthemes (>= 4.2.4), tidyverse (>= 2.0.0), + data.table (>= 1.14.8), + formattable (>= 0.2.1), + rdbounds (>= 1.1), lubridate (>= 1.9.2), rio (>= 0.5.29), xtable (>= 1.8.4), @@ -42,5 +45,6 @@ Imports: synthdid (>= 0.0.9), plm (>= 2.6.3), MASS, + MedBounds (>= 0.1.0), foreach (>= 1.5.2) VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 5ef4db0..3b92de6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ export(ama_theme) export(balance_assessment) export(balance_scatter_custom) export(get_balanced_panel) +export(lee_bounds) export(med_ind) export(nice_tab) export(panel_estimate) @@ -17,6 +18,7 @@ export(plot_coef_par_trends) export(plot_covariate_balance_pretrend) export(plot_density_by_treatment) export(plot_par_trends) +export(plot_rd_aa_share) export(plot_treat_time) export(plot_trends_across_group) export(process_panel_estimate) @@ -27,11 +29,15 @@ export(synthdid_est_per) export(synthdid_plot_ate) export(synthdid_se_jacknife) export(synthdid_se_placebo) +import(data.table) +import(formattable) import(ggplot2) import(lubridate) +import(rdbounds) import(rio) import(xtable) importFrom(Hotelling,hotelling.test) +importFrom(MedBounds,compute_bounds_ats) importFrom(PanelMatch,PanelMatch) importFrom(PanelMatch,get_covariate_balance) importFrom(dplyr,"%>%") @@ -41,6 +47,7 @@ importFrom(dplyr,mutate) importFrom(dplyr,rowwise) importFrom(dplyr,select) importFrom(dplyr,summarise) +importFrom(dplyr,summarise_all) importFrom(dplyr,ungroup) importFrom(fixest,coefplot) importFrom(fixest,feols) diff --git a/R/lee_bounds.R b/R/lee_bounds.R new file mode 100644 index 0000000..60ec1da --- /dev/null +++ b/R/lee_bounds.R @@ -0,0 +1,66 @@ +#' Summarize Lee Bounds for Always-Takers +#' +#' Computes and summarizes the Lee bounds on the average direct effect for always-takers (ATs) for whom there is a direct effect of treatment (D) on the outcome (Y). This function utilizes \code{\link[MedBounds]{compute_bounds_ats}} to calculate initial bounds and applies bootstrapping to estimate the standard deviation of these estimates, providing a summary in a data frame format. +#' +#' @param df A data frame containing the data. +#' @param d Name of the treatment variable in \code{df}. +#' @param m Name of the mediator variable in \code{df}. +#' @param y Name of the outcome variable in \code{df}. +#' @param cluster (Optional) The name of the cluster variable for clustered bootstrapping. +#' @param c_at_ratio (Optional) Specifies the ratio of E[Y(1,1) | C]/E[Y(1,1) | AT]. If this is specified, the direct effect for ATs is point-identified. +#' @param units A string denoting the units of the outcome variable (for labeling purposes). +#' @param numdraws The number of bootstrap draws for estimating the standard deviation. +#' @return A data frame summarizing the computed bounds with terms, estimates, and standard errors. +#' @examples +#' \dontrun{ +#' data(example_data) +#' summarized_bounds <- lee_bounds(df = example_data, d = "treatment", m = "mediator", y = "outcome") +#' } +#' @export +#' @importFrom MedBounds compute_bounds_ats +#' @importFrom dplyr summarise_all +lee_bounds <- function(df, d, m, y, cluster = NULL, c_at_ratio = NULL, units = "", numdraws = 1000) { + # Compute the point estimate using MedBounds::compute_bounds_ats + pt_estimate <- MedBounds::compute_bounds_ats( + df = df, + d = d, + m = m, + y = y, + c_at_ratio = c_at_ratio + ) + + # Compute bootstrap draws with optional clustering + bootstrap_draws <- MedBounds:::compute_bootstrap_draws_clustered( + df = df, + d = d, + m = m, + y = y, + f = function(..., c_at_ratio_) { + MedBounds::compute_bounds_ats(..., c_at_ratio = c_at_ratio) + }, + cluster = cluster, + fix_n1 = FALSE, + numdraws = numdraws + ) + + # Use dplyr to summarise and compute the standard deviation of the columns of bootstrap_draws + bootstrap_sds <- bootstrap_draws %>% + summarise_all(sd) + + # Determine the term list based on the presence of c_at_ratio + termlist <- if (is.null(c_at_ratio)) { + c("Lower bound", "Upper bound") + } else { + "Point estimate" + } + + # Tidy the results into a data frame + tidy_results <- data.frame( + term = termlist, + estimate = as.numeric(pt_estimate), + std.error = as.numeric(bootstrap_sds), + stringsAsFactors = FALSE + ) + + return(tidy_results) +} diff --git a/R/plot_rd_aa_share.R b/R/plot_rd_aa_share.R new file mode 100644 index 0000000..8c04abb --- /dev/null +++ b/R/plot_rd_aa_share.R @@ -0,0 +1,114 @@ +#' Plot RD Always-assigned Share +#' +#' This function creates a plot for the share of always-assigned units +#' in a Regression Discontinuity (RD) design, either Sharp RD (SRD) or +#' Fuzzy RD (FRD). It provides options to include various confidence +#' intervals and reference lines. +#' +#' @param data The output object from the \code{rdbounds} function. +#' @param rd_type The type of RD design, either "SRD" for Sharp RD or "FRD" +#' for Fuzzy RD. Default is "SRD". +#' @param x_label The label for the x-axis. Default is "Share of Always-assigned Units". +#' @param y_label The label for the y-axis. Default is "ATE". +#' @param plot_title The title of the plot. Default is an empty string. +#' @param theme_use A ggplot2 theme function to apply to the plot. Default is +#' \code{causalverse::ama_theme()}. +#' @param tau Logical, whether to include a vertical line at the estimated +#' treatment effect. Default is TRUE. +#' @param tau_CI Logical, whether to include confidence intervals for the +#' treatment effect estimate. Default is FALSE. +#' @param bounds_CI Logical, whether to include confidence intervals for the +#' manipulation bounds. Default is TRUE. +#' @param ref_line The y-intercept for a reference line. Default is 0. +#' @param ... Additional arguments passed to \code{labs} in ggplot2. +#' +#' @return A ggplot object. +#' @import ggplot2 +#' @import formattable +#' @import data.table +#' @import rdbounds +#' @examples +#' \dontrun{ +#' set.seed(1) +#' data <- rdbounds::rdbounds_sampledata(10000, covs = FALSE) +#' rdbounds_est_tau <- rdbounds::rdbounds( +#' y = data$y, +#' x = data$x, +#' treatment = data$treatment, +#' c = 0, +#' discrete_x = FALSE, +#' discrete_y = FALSE, +#' bwsx = c(.2, .5), +#' bwy = 1, +#' kernel = "epanechnikov", +#' orders = 1, +#' evaluation_ys = seq(from = 0, to = 15, by = 1), +#' refinement_A = TRUE, +#' refinement_B = TRUE, +#' right_effects = TRUE, +#' potential_taus = c(.025, .05, .1, .2), +#' yextremes = c(0, 15), +#' num_bootstraps = 5 +#' ) +#' plot_rd_aa_share(rdbounds_est_tau) +#' } +#' @export +plot_rd_aa_share <- function(data, + rd_type = "SRD", + x_label = "Share of Always-assigned Units", + y_label = "ATE", + plot_title = "", + theme_use = causalverse::ama_theme(), + tau = TRUE, + tau_CI = FALSE, + bounds_CI = TRUE, + ref_line = 0, + ...) { + + # Determine the correct prefix based on rd_type + prefix <- if (rd_type == "FRD") "FRD" else "SRD" + + # Extract the necessary data from the rdbounds_est_tau object + df <- as.data.frame(data$estimates[,1][[paste0("TE_", prefix, "_CIs_manipulation")]]) + naive_estimate <- data$estimates[,1][[paste0("TE_", prefix, "_naive")]] + tau_hat <- data$estimates[,1]$tau_hat + tau_hat_CI <- data$estimates[,1]$tau_hat_CI + + # Create the plot + p <- ggplot(df, aes(x = potential_taus)) + + geom_point(aes(y = TE_lower), size = 3, color = "black") + + geom_point(aes(y = TE_upper), size = 3, color = "black") + + geom_line(aes(y = TE_lower), linetype = "solid", color = "black") + + geom_line(aes(y = TE_upper), linetype = "solid", color = "black") + + geom_line(aes(y = get(paste0("TE_", prefix, "_CIs_manipulation_lower"))), linetype = "dotted", color = "black") + + geom_line(aes(y = get(paste0("TE_", prefix, "_CIs_manipulation_upper"))), linetype = "dotted", color = "black") + + annotate("point", x = 0, y = naive_estimate, size = 3, color = "black") + + labs(x = x_label, y = y_label, title = plot_title, ...) + + theme_use + + # Add reference line + if (!is.null(ref_line)) { + p <- p + geom_hline(yintercept = ref_line, linetype = "dashed", color = "red") + } + + # Add vertical line for tau_hat + if (tau) { + p <- p + geom_vline(xintercept = round(tau_hat, 3), linetype = "solid", color = "black") + } + + # Add confidence intervals for tau_hat + if (tau_CI) { + p <- p + + geom_vline(xintercept = round(tau_hat_CI, 3)[1], linetype = "dotted", color = "black") + + geom_vline(xintercept = round(tau_hat_CI, 3)[2], linetype = "dotted", color = "black") + } + + # Add manipulation bounds confidence intervals + if (bounds_CI) { + p <- p + + geom_line(aes(y = get(paste0("TE_", prefix, "_CIs_manipulation_lower"))), linetype = "dotted", color = "black") + + geom_line(aes(y = get(paste0("TE_", prefix, "_CIs_manipulation_upper"))), linetype = "dotted", color = "black") + } + + return(p) +} diff --git a/causalverse_0.0.0.9000.pdf b/causalverse_0.0.0.9000.pdf index 46ad349..838b3f0 100644 Binary files a/causalverse_0.0.0.9000.pdf and b/causalverse_0.0.0.9000.pdf differ diff --git a/docs/articles/a_introduction.html b/docs/articles/a_introduction.html index d172a35..bec2bc1 100644 --- a/docs/articles/a_introduction.html +++ b/docs/articles/a_introduction.html @@ -91,7 +91,7 @@

Introduction to CausalVerse

Mike Nguyen

-

2024-03-10

+

2024-05-13

diff --git a/docs/articles/b_synthdid.html b/docs/articles/b_synthdid.html index 47cfdcd..f55088c 100644 --- a/docs/articles/b_synthdid.html +++ b/docs/articles/b_synthdid.html @@ -91,7 +91,7 @@

3. Synthetic Difference-in-Differences

Mike Nguyen

-

2024-03-10

+

2024-05-13

diff --git a/docs/articles/c_did.html b/docs/articles/c_did.html index 9179d31..048a412 100644 --- a/docs/articles/c_did.html +++ b/docs/articles/c_did.html @@ -91,7 +91,7 @@

4. Difference-in-Differences

Mike Nguyen

-

2024-03-10

+

2024-05-13

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index a95dd27..cfbc736 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -5,5 +5,5 @@ articles: a_introduction: a_introduction.html b_synthdid: b_synthdid.html c_did: c_did.html -last_built: 2024-03-11T02:58Z +last_built: 2024-05-14T01:19Z diff --git a/docs/reference/index.html b/docs/reference/index.html index a2574d2..2bdef28 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -99,6 +99,10 @@

All functions get_balanced_panel()

Extract a Balanced Panel

+ +

lee_bounds()

+ +

Summarize Lee Bounds for Always-Takers

med_ind()

@@ -131,6 +135,10 @@

All functions plot_par_trends()

Plot Parallel Trends

+ +

plot_rd_aa_share()

+ +

Plot RD Always-assigned Share

plot_treat_time()

diff --git a/docs/reference/lee_bounds.html b/docs/reference/lee_bounds.html new file mode 100644 index 0000000..4281656 --- /dev/null +++ b/docs/reference/lee_bounds.html @@ -0,0 +1,153 @@ + +Summarize Lee Bounds for Always-Takers — lee_bounds • causalverse + + +
+
+ + + +
+
+ + +
+

Computes and summarizes the Lee bounds on the average direct effect for always-takers (ATs) for whom there is a direct effect of treatment (D) on the outcome (Y). This function utilizes compute_bounds_ats to calculate initial bounds and applies bootstrapping to estimate the standard deviation of these estimates, providing a summary in a data frame format.

+
+ +
+
lee_bounds(
+  df,
+  d,
+  m,
+  y,
+  cluster = NULL,
+  c_at_ratio = NULL,
+  units = "",
+  numdraws = 1000
+)
+
+ +
+

Arguments

+
df
+

A data frame containing the data.

+ + +
d
+

Name of the treatment variable in df.

+ + +
m
+

Name of the mediator variable in df.

+ + +
y
+

Name of the outcome variable in df.

+ + +
cluster
+

(Optional) The name of the cluster variable for clustered bootstrapping.

+ + +
c_at_ratio
+

(Optional) Specifies the ratio of EY(1,1) | C/EY(1,1) | AT. If this is specified, the direct effect for ATs is point-identified.

+ + +
units
+

A string denoting the units of the outcome variable (for labeling purposes).

+ + +
numdraws
+

The number of bootstrap draws for estimating the standard deviation.

+ +
+
+

Value

+ + +

A data frame summarizing the computed bounds with terms, estimates, and standard errors.

+
+ +
+

Examples

+
if (FALSE) {
+data(example_data)
+summarized_bounds <- lee_bounds(df = example_data, d = "treatment", m = "mediator", y = "outcome")
+}
+
+
+
+ +
+ + +
+ +
+

Site built with pkgdown 2.0.7.

+
+ +
+ + + + + + + + diff --git a/docs/reference/plot_rd_aa_share.html b/docs/reference/plot_rd_aa_share.html new file mode 100644 index 0000000..08a3917 --- /dev/null +++ b/docs/reference/plot_rd_aa_share.html @@ -0,0 +1,199 @@ + +Plot RD Always-assigned Share — plot_rd_aa_share • causalverse + + +
+
+ + + +
+
+ + +
+

This function creates a plot for the share of always-assigned units +in a Regression Discontinuity (RD) design, either Sharp RD (SRD) or +Fuzzy RD (FRD). It provides options to include various confidence +intervals and reference lines.

+
+ +
+
plot_rd_aa_share(
+  data,
+  rd_type = "SRD",
+  x_label = "Share of Always-assigned Units",
+  y_label = "ATE",
+  plot_title = "",
+  theme_use = causalverse::ama_theme(),
+  tau = TRUE,
+  tau_CI = FALSE,
+  bounds_CI = TRUE,
+  ref_line = 0,
+  ...
+)
+
+ +
+

Arguments

+
data
+

The output object from the rdbounds function.

+ + +
rd_type
+

The type of RD design, either "SRD" for Sharp RD or "FRD" +for Fuzzy RD. Default is "SRD".

+ + +
x_label
+

The label for the x-axis. Default is "Share of Always-assigned Units".

+ + +
y_label
+

The label for the y-axis. Default is "ATE".

+ + +
plot_title
+

The title of the plot. Default is an empty string.

+ + +
theme_use
+

A ggplot2 theme function to apply to the plot. Default is +causalverse::ama_theme().

+ + +
tau
+

Logical, whether to include a vertical line at the estimated +treatment effect. Default is TRUE.

+ + +
tau_CI
+

Logical, whether to include confidence intervals for the +treatment effect estimate. Default is FALSE.

+ + +
bounds_CI
+

Logical, whether to include confidence intervals for the +manipulation bounds. Default is TRUE.

+ + +
ref_line
+

The y-intercept for a reference line. Default is 0.

+ + +
...
+

Additional arguments passed to labs in ggplot2.

+ +
+
+

Value

+ + +

A ggplot object.

+
+ +
+

Examples

+
if (FALSE) {
+set.seed(1)
+data <- rdbounds::rdbounds_sampledata(10000, covs = FALSE)
+rdbounds_est_tau <- rdbounds::rdbounds(
+    y = data$y,
+    x = data$x,
+    treatment = data$treatment,
+    c = 0,
+    discrete_x = FALSE,
+    discrete_y = FALSE,
+    bwsx = c(.2, .5),
+    bwy = 1,
+    kernel = "epanechnikov",
+    orders = 1,
+    evaluation_ys = seq(from = 0, to = 15, by = 1),
+    refinement_A = TRUE,
+    refinement_B = TRUE,
+    right_effects = TRUE,
+    potential_taus = c(.025, .05, .1, .2),
+    yextremes = c(0, 15),
+    num_bootstraps = 5
+)
+plot_rd_aa_share(rdbounds_est_tau)
+}
+
+
+
+ +
+ + +
+ +
+

Site built with pkgdown 2.0.7.

+
+ +
+ + + + + + + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 5c35c43..d127a94 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -105,6 +105,9 @@ /reference/index.html + + /reference/lee_bounds.html + /reference/med_ind.html @@ -129,6 +132,9 @@ /reference/plot_par_trends.html + + /reference/plot_rd_aa_share.html + /reference/plot_treat_time.html diff --git a/man/lee_bounds.Rd b/man/lee_bounds.Rd new file mode 100644 index 0000000..8c8f878 --- /dev/null +++ b/man/lee_bounds.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/lee_bounds.R +\name{lee_bounds} +\alias{lee_bounds} +\title{Summarize Lee Bounds for Always-Takers} +\usage{ +lee_bounds( + df, + d, + m, + y, + cluster = NULL, + c_at_ratio = NULL, + units = "", + numdraws = 1000 +) +} +\arguments{ +\item{df}{A data frame containing the data.} + +\item{d}{Name of the treatment variable in \code{df}.} + +\item{m}{Name of the mediator variable in \code{df}.} + +\item{y}{Name of the outcome variable in \code{df}.} + +\item{cluster}{(Optional) The name of the cluster variable for clustered bootstrapping.} + +\item{c_at_ratio}{(Optional) Specifies the ratio of E\link{Y(1,1) | C}/E\link{Y(1,1) | AT}. If this is specified, the direct effect for ATs is point-identified.} + +\item{units}{A string denoting the units of the outcome variable (for labeling purposes).} + +\item{numdraws}{The number of bootstrap draws for estimating the standard deviation.} +} +\value{ +A data frame summarizing the computed bounds with terms, estimates, and standard errors. +} +\description{ +Computes and summarizes the Lee bounds on the average direct effect for always-takers (ATs) for whom there is a direct effect of treatment (D) on the outcome (Y). This function utilizes \code{\link[MedBounds]{compute_bounds_ats}} to calculate initial bounds and applies bootstrapping to estimate the standard deviation of these estimates, providing a summary in a data frame format. +} +\examples{ +\dontrun{ +data(example_data) +summarized_bounds <- lee_bounds(df = example_data, d = "treatment", m = "mediator", y = "outcome") +} +} diff --git a/man/plot_rd_aa_share.Rd b/man/plot_rd_aa_share.Rd new file mode 100644 index 0000000..c818f64 --- /dev/null +++ b/man/plot_rd_aa_share.Rd @@ -0,0 +1,83 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot_rd_aa_share.R +\name{plot_rd_aa_share} +\alias{plot_rd_aa_share} +\title{Plot RD Always-assigned Share} +\usage{ +plot_rd_aa_share( + data, + rd_type = "SRD", + x_label = "Share of Always-assigned Units", + y_label = "ATE", + plot_title = "", + theme_use = causalverse::ama_theme(), + tau = TRUE, + tau_CI = FALSE, + bounds_CI = TRUE, + ref_line = 0, + ... +) +} +\arguments{ +\item{data}{The output object from the \code{rdbounds} function.} + +\item{rd_type}{The type of RD design, either "SRD" for Sharp RD or "FRD" +for Fuzzy RD. Default is "SRD".} + +\item{x_label}{The label for the x-axis. Default is "Share of Always-assigned Units".} + +\item{y_label}{The label for the y-axis. Default is "ATE".} + +\item{plot_title}{The title of the plot. Default is an empty string.} + +\item{theme_use}{A ggplot2 theme function to apply to the plot. Default is +\code{causalverse::ama_theme()}.} + +\item{tau}{Logical, whether to include a vertical line at the estimated +treatment effect. Default is TRUE.} + +\item{tau_CI}{Logical, whether to include confidence intervals for the +treatment effect estimate. Default is FALSE.} + +\item{bounds_CI}{Logical, whether to include confidence intervals for the +manipulation bounds. Default is TRUE.} + +\item{ref_line}{The y-intercept for a reference line. Default is 0.} + +\item{...}{Additional arguments passed to \code{labs} in ggplot2.} +} +\value{ +A ggplot object. +} +\description{ +This function creates a plot for the share of always-assigned units +in a Regression Discontinuity (RD) design, either Sharp RD (SRD) or +Fuzzy RD (FRD). It provides options to include various confidence +intervals and reference lines. +} +\examples{ +\dontrun{ +set.seed(1) +data <- rdbounds::rdbounds_sampledata(10000, covs = FALSE) +rdbounds_est_tau <- rdbounds::rdbounds( + y = data$y, + x = data$x, + treatment = data$treatment, + c = 0, + discrete_x = FALSE, + discrete_y = FALSE, + bwsx = c(.2, .5), + bwy = 1, + kernel = "epanechnikov", + orders = 1, + evaluation_ys = seq(from = 0, to = 15, by = 1), + refinement_A = TRUE, + refinement_B = TRUE, + right_effects = TRUE, + potential_taus = c(.025, .05, .1, .2), + yextremes = c(0, 15), + num_bootstraps = 5 +) +plot_rd_aa_share(rdbounds_est_tau) +} +} diff --git a/temp/archive/test_est_2024-03-12.tex b/temp/archive/test_est_2024-03-12.tex new file mode 100644 index 0000000..77b9213 --- /dev/null +++ b/temp/archive/test_est_2024-03-12.tex @@ -0,0 +1,29 @@ + +\begingroup +\centering +\begin{tabular}{lccc} + \tabularnewline \midrule \midrule + Dependent Variable: & \multicolumn{3}{c}{Ozone}\\ + Model: & (1) & (2) & (3)\\ + \midrule + \emph{Variables}\\ + Constant & 18.60$^{***}$ & 77.25$^{***}$ & -64.34$^{***}$\\ + & (6.748) & (9.068) & (23.05)\\ + Solar.R & 0.1272$^{***}$ & 0.1004$^{***}$ & 0.0598$^{**}$\\ + & (0.0328) & (0.0263) & (0.0232)\\ + Wind & & -5.402$^{***}$ & -3.334$^{***}$\\ + & & (0.6732) & (0.6544)\\ + Temp & & & 1.652$^{***}$\\ + & & & (0.2535)\\ + \midrule + \emph{Fit statistics}\\ + Observations & 111 & 111 & 111\\ + R$^2$ & 0.12134 & 0.44949 & 0.60589\\ + Adjusted R$^2$ & 0.11328 & 0.43930 & 0.59484\\ + \midrule \midrule + \multicolumn{4}{l}{\emph{IID standard-errors in parentheses}}\\ + \multicolumn{4}{l}{\emph{Signif. Codes: ***: 0.01, **: 0.05, *: 0.1}}\\ +\end{tabular} +\par\endgroup + + diff --git a/temp/archive/test_est_2024-03-12.xlsx b/temp/archive/test_est_2024-03-12.xlsx new file mode 100644 index 0000000..cf9b733 Binary files /dev/null and b/temp/archive/test_est_2024-03-12.xlsx differ diff --git a/temp/test_est.tex b/temp/test_est.tex new file mode 100644 index 0000000..77b9213 --- /dev/null +++ b/temp/test_est.tex @@ -0,0 +1,29 @@ + +\begingroup +\centering +\begin{tabular}{lccc} + \tabularnewline \midrule \midrule + Dependent Variable: & \multicolumn{3}{c}{Ozone}\\ + Model: & (1) & (2) & (3)\\ + \midrule + \emph{Variables}\\ + Constant & 18.60$^{***}$ & 77.25$^{***}$ & -64.34$^{***}$\\ + & (6.748) & (9.068) & (23.05)\\ + Solar.R & 0.1272$^{***}$ & 0.1004$^{***}$ & 0.0598$^{**}$\\ + & (0.0328) & (0.0263) & (0.0232)\\ + Wind & & -5.402$^{***}$ & -3.334$^{***}$\\ + & & (0.6732) & (0.6544)\\ + Temp & & & 1.652$^{***}$\\ + & & & (0.2535)\\ + \midrule + \emph{Fit statistics}\\ + Observations & 111 & 111 & 111\\ + R$^2$ & 0.12134 & 0.44949 & 0.60589\\ + Adjusted R$^2$ & 0.11328 & 0.43930 & 0.59484\\ + \midrule \midrule + \multicolumn{4}{l}{\emph{IID standard-errors in parentheses}}\\ + \multicolumn{4}{l}{\emph{Signif. Codes: ***: 0.01, **: 0.05, *: 0.1}}\\ +\end{tabular} +\par\endgroup + + diff --git a/temp/test_est.xlsx b/temp/test_est.xlsx new file mode 100644 index 0000000..d8b3429 Binary files /dev/null and b/temp/test_est.xlsx differ diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf index bc146df..49e20c1 100644 Binary files a/tests/testthat/Rplots.pdf and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/test-lee_bounds.R b/tests/testthat/test-lee_bounds.R new file mode 100644 index 0000000..f4a3d32 --- /dev/null +++ b/tests/testthat/test-lee_bounds.R @@ -0,0 +1,22 @@ +library(testthat) +library(MedBounds) # Assuming MedBounds provides the necessary data/functions +library(dplyr) + +# Sample data for testing +set.seed(123) # Set seed for reproducibility +example_data <- data.frame( + d = sample(0:1, 100, replace = TRUE), + m = rnorm(100), + y = rnorm(100), + cluster = sample(1:10, 100, replace = TRUE) +) + + +# Test case: With c_at_ratio specified +test_that("lee_bounds with c_at_ratio specified returns correct term", { + result <- lee_bounds(df = example_data, d = "d", m = "m", y = "y", c_at_ratio = 0.5, numdraws = 10) + + # Check the term column for "Point estimate" since c_at_ratio is specified + expect_true("Point estimate" %in% result$term) +}) + diff --git a/tests/testthat/test-plot_rd_aa_share.R b/tests/testthat/test-plot_rd_aa_share.R new file mode 100644 index 0000000..e69de29 diff --git a/tests/testthat/test-synthdid_plot_ate.R b/tests/testthat/test-synthdid_plot_ate.R index e4fd569..6cc2241 100644 --- a/tests/testthat/test-synthdid_plot_ate.R +++ b/tests/testthat/test-synthdid_plot_ate.R @@ -22,6 +22,6 @@ est <- ) test_that("synthdid_plot returns a ggplot object", { - plot <- synthdid_plot(est) + plot <- synthdid_plot_ate(est) expect_true(is.ggplot(plot)) })