Skip to content

Example Usage

Vansh Gupta edited this page Jul 20, 2022 · 2 revisions

R Code Example

This is a basic example which shows you how to use the package in one scenario:

library(STE)
## Basic Example Code:

# Load cb_startups as a dataframe from cb_startups.Rdata file.
load("cb_startups.Rdata")

# Estimate the main effect of the treatment.
reg <- estimate_main_effect(
    y_var = "equity_growth",
    treatment_var = "bearly_stage_has_vc",
    X = cb_startups[, ml_vars],
    data_df = cb_startups
)
print(summary(reg))

# Estimate the propensity score of the treatment.
p_scores <- estimate_propensity(
    treatment = cb_startups$bearly_stage_has_vc,
    X = cb_startups[, ml_vars]
)

# Estimate the strategic treatment effect.
cb_startups <- estimate_ste(
    y = cb_startups$equity_growth,
    treatment = cb_startups$bearly_stage_has_vc,
    propensity = p_scores,
    df = cb_startups
)

# Remove NA values for analysis. 
cb_startups.clean <- cb_startups %>%
    filter(!is.na(ste))

# Study the determinants of STE.
ste_features <- STE::get_top_ste_determinants(
    ste = cb_startups.clean$ste,
    X = cb_startups.clean[, ml_vars],
    teffect = cb_startups.clean$teffect
    )
View(ste_features)

# Estimate the coherence value.
ml_vars.no_inter <- ml_vars[grep("^[^X]",ml_vars)]
coherence_value <- STE::estimate_coherence(
    y = cb_startups.clean$teffect,
    x = cb_startups.clean[, ml_vars],
    x.no_inter = cb_startups.clean[, ml_vars.no_inter]
)
print(paste0("Coherence Value: ",coherence_value))
Clone this wiki locally