dedefo <- # Load necessary libraries
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.4.3
## Warning: package 'ggplot2' was built under R version 4.4.3
## Warning: package 'tibble' was built under R version 4.4.3
## Warning: package 'tidyr' was built under R version 4.4.3
## Warning: package 'readr' was built under R version 4.4.3
## Warning: package 'purrr' was built under R version 4.4.3
## Warning: package 'dplyr' was built under R version 4.4.3
## Warning: package 'stringr' was built under R version 4.4.3
## Warning: package 'forcats' was built under R version 4.4.3
## Warning: package 'lubridate' was built under R version 4.4.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(broom)
## Warning: package 'broom' was built under R version 4.4.3
library(stargazer)
## 
## Please cite as: 
## 
##  Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(ggplot2)
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 4.4.3
## 
## Attaching package: 'gridExtra'
## 
## The following object is masked from 'package:dplyr':
## 
##     combine
# Create a simulated dataset based on the regression coefficients provided
set.seed(123)  # For reproducibility

# Number of observations for each category
n_dem_incumbent <- 100
n_dem_challenger <- 100
n_dem_open <- 50
n_rep_incumbent <- 80
n_rep_challenger <- 120
n_rep_open <- 69

# Create the dataset structure first
women_candidates <- data.frame(
  candidate_id = 1:519,
  party = c(
    rep("Democratic", n_dem_incumbent + n_dem_challenger + n_dem_open),
    rep("Republican", n_rep_incumbent + n_rep_challenger + n_rep_open)
  ),
  incumbency = c(
    rep("Incumbent", n_dem_incumbent),
    rep("Challenger", n_dem_challenger),
    rep("Non-Incumbent", n_dem_open),
    rep("Incumbent", n_rep_incumbent),
    rep("Challenger", n_rep_challenger),
    rep("Non-Incumbent", n_rep_open)
  ),
  # Initialize the financial variables
  receipts = NA,
  contributions = NA,
  disbursements = NA
)

# Function to generate values based on regression coefficients
generate_data <- function(n, party_coef, incumbency_coef, interaction_coef = 0, base_intercept = -6.067, sd = 5.324) {
  # Generate data with error term
  y_base <- base_intercept + party_coef + incumbency_coef + interaction_coef
  y <- rnorm(n, mean = y_base, sd = sd)
  
  # Exponentiate to get back from log scale
  receipt_values <- exp(y)
  
  return(receipt_values)
}

# Identify indices for each group
dem_inc_idx <- which(women_candidates$party == "Democratic" & women_candidates$incumbency == "Incumbent")
dem_chl_idx <- which(women_candidates$party == "Democratic" & women_candidates$incumbency == "Challenger")
dem_non_idx <- which(women_candidates$party == "Democratic" & women_candidates$incumbency == "Non-Incumbent")
rep_inc_idx <- which(women_candidates$party == "Republican" & women_candidates$incumbency == "Incumbent")
rep_chl_idx <- which(women_candidates$party == "Republican" & women_candidates$incumbency == "Challenger")
rep_non_idx <- which(women_candidates$party == "Republican" & women_candidates$incumbency == "Non-Incumbent")

# Generate values for receipts based on coefficients
women_candidates$receipts[dem_inc_idx] <- generate_data(length(dem_inc_idx), 0, 0)
women_candidates$receipts[dem_chl_idx] <- generate_data(length(dem_chl_idx), 0, -5.065)
women_candidates$receipts[dem_non_idx] <- generate_data(length(dem_non_idx), 0, 6.081)
women_candidates$receipts[rep_inc_idx] <- generate_data(length(rep_inc_idx), -7.268, 0)
women_candidates$receipts[rep_chl_idx] <- generate_data(length(rep_chl_idx), -7.268, -5.065, 5.455)
women_candidates$receipts[rep_non_idx] <- generate_data(length(rep_non_idx), -7.268, 6.081, 15.148)

# Generate values for individual contributions
women_candidates$contributions[dem_inc_idx] <- generate_data(length(dem_inc_idx), 0, 0, 0, -5.746, 5.225)
women_candidates$contributions[dem_chl_idx] <- generate_data(length(dem_chl_idx), 0, -5.034, 0, -5.746, 5.225)
women_candidates$contributions[dem_non_idx] <- generate_data(length(dem_non_idx), 0, 5.447, 0, -5.746, 5.225)
women_candidates$contributions[rep_inc_idx] <- generate_data(length(rep_inc_idx), -7.329, 0, 0, -5.746, 5.225)
women_candidates$contributions[rep_chl_idx] <- generate_data(length(rep_chl_idx), -7.329, -5.034, 5.037, -5.746, 5.225)
women_candidates$contributions[rep_non_idx] <- generate_data(length(rep_non_idx), -7.329, 5.447, 14.466, -5.746, 5.225)

# Generate values for disbursements
women_candidates$disbursements[dem_inc_idx] <- generate_data(length(dem_inc_idx), 0, 0, 0, -6.158, 5.315)
women_candidates$disbursements[dem_chl_idx] <- generate_data(length(dem_chl_idx), 0, -5.235, 0, -6.158, 5.315)
women_candidates$disbursements[dem_non_idx] <- generate_data(length(dem_non_idx), 0, 6.089, 0, -6.158, 5.315)
women_candidates$disbursements[rep_inc_idx] <- generate_data(length(rep_inc_idx), -7.305, 0, 0, -6.158, 5.315)
women_candidates$disbursements[rep_chl_idx] <- generate_data(length(rep_chl_idx), -7.305, -5.235, 5.596, -6.158, 5.315)
women_candidates$disbursements[rep_non_idx] <- generate_data(length(rep_non_idx), -7.305, 6.089, 15.221, -6.158, 5.315)

# Create factor variables for regression
women_candidates$party_factor <- factor(women_candidates$party, levels = c("Democratic", "Republican"))
women_candidates$incumbency_factor <- factor(women_candidates$incumbency, levels = c("Incumbent", "Challenger", "Non-Incumbent"))

# Transform back to log scale for regression
women_candidates$log_receipts <- log(women_candidates$receipts)
women_candidates$log_contributions <- log(women_candidates$contributions)
women_candidates$log_disbursements <- log(women_candidates$disbursements)

# Check if we have any missing values
sum(is.na(women_candidates$receipts))
## [1] 0
sum(is.na(women_candidates$contributions))
## [1] 0
sum(is.na(women_candidates$disbursements))
## [1] 0
# Run the regression models
model1 <- lm(log_receipts ~ party_factor + incumbency_factor + party_factor:incumbency_factor, data = women_candidates)
model2 <- lm(log_contributions ~ party_factor + incumbency_factor + party_factor:incumbency_factor, data = women_candidates)
model3 <- lm(log_disbursements ~ party_factor + incumbency_factor + party_factor:incumbency_factor, data = women_candidates)

# View the regression results
summary(model1)
## 
## Call:
## lm(formula = log_receipts ~ party_factor + incumbency_factor + 
##     party_factor:incumbency_factor, data = women_candidates)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -14.8258  -3.3599  -0.1442   3.3367  17.8279 
## 
## Coefficients:
##                                                       Estimate Std. Error
## (Intercept)                                            -5.5857     0.5149
## party_factorRepublican                                 -6.7813     0.7723
## incumbency_factorChallenger                            -6.1189     0.7282
## incumbency_factorNon-Incumbent                          5.5543     0.8918
## party_factorRepublican:incumbency_factorChallenger      5.1427     1.0404
## party_factorRepublican:incumbency_factorNon-Incumbent  15.3657     1.2292
##                                                       t value Pr(>|t|)    
## (Intercept)                                           -10.848  < 2e-16 ***
## party_factorRepublican                                 -8.780  < 2e-16 ***
## incumbency_factorChallenger                            -8.403 4.30e-16 ***
## incumbency_factorNon-Incumbent                          6.228 9.84e-10 ***
## party_factorRepublican:incumbency_factorChallenger      4.943 1.04e-06 ***
## party_factorRepublican:incumbency_factorNon-Incumbent  12.501  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.149 on 513 degrees of freedom
## Multiple R-squared:  0.6781, Adjusted R-squared:  0.6749 
## F-statistic: 216.1 on 5 and 513 DF,  p-value: < 2.2e-16
summary(model2)
## 
## Call:
## lm(formula = log_contributions ~ party_factor + incumbency_factor + 
##     party_factor:incumbency_factor, data = women_candidates)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -14.3745  -3.4934   0.0451   3.5514  14.5575 
## 
## Coefficients:
##                                                       Estimate Std. Error
## (Intercept)                                            -6.0526     0.5390
## party_factorRepublican                                 -7.2110     0.8085
## incumbency_factorChallenger                            -5.0987     0.7622
## incumbency_factorNon-Incumbent                          7.0385     0.9336
## party_factorRepublican:incumbency_factorChallenger      5.8369     1.0891
## party_factorRepublican:incumbency_factorNon-Incumbent  13.3041     1.2867
##                                                       t value Pr(>|t|)    
## (Intercept)                                           -11.230  < 2e-16 ***
## party_factorRepublican                                 -8.919  < 2e-16 ***
## incumbency_factorChallenger                            -6.689 5.89e-11 ***
## incumbency_factorNon-Incumbent                          7.539 2.16e-13 ***
## party_factorRepublican:incumbency_factorChallenger      5.359 1.27e-07 ***
## party_factorRepublican:incumbency_factorNon-Incumbent  10.339  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.39 on 513 degrees of freedom
## Multiple R-squared:  0.6307, Adjusted R-squared:  0.6271 
## F-statistic: 175.3 on 5 and 513 DF,  p-value: < 2.2e-16
summary(model3)
## 
## Call:
## lm(formula = log_disbursements ~ party_factor + incumbency_factor + 
##     party_factor:incumbency_factor, data = women_candidates)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -14.3651  -3.4088   0.0327   3.3853  18.1439 
## 
## Coefficients:
##                                                       Estimate Std. Error
## (Intercept)                                            -6.0158     0.5091
## party_factorRepublican                                 -7.5712     0.7637
## incumbency_factorChallenger                            -6.0018     0.7200
## incumbency_factorNon-Incumbent                          6.8871     0.8818
## party_factorRepublican:incumbency_factorChallenger      6.5263     1.0288
## party_factorRepublican:incumbency_factorNon-Incumbent  15.8014     1.2154
##                                                       t value Pr(>|t|)    
## (Intercept)                                           -11.816  < 2e-16 ***
## party_factorRepublican                                 -9.914  < 2e-16 ***
## incumbency_factorChallenger                            -8.336 7.10e-16 ***
## incumbency_factorNon-Incumbent                          7.810 3.24e-14 ***
## party_factorRepublican:incumbency_factorChallenger      6.344 4.93e-10 ***
## party_factorRepublican:incumbency_factorNon-Incumbent  13.001  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.091 on 513 degrees of freedom
## Multiple R-squared:  0.7028, Adjusted R-squared:  0.6999 
## F-statistic: 242.6 on 5 and 513 DF,  p-value: < 2.2e-16
# Create nicer regression table
stargazer(model1, model2, model3, 
          type = "text",
          dep.var.labels = c("Log Receipts", "Log Individual Contributions", "Log Disbursements"),
          covariate.labels = c("Intercept (Democratic Incumbent)", 
                              "Party: Republican", 
                              "Incumbency: Challenger",
                              "Incumbency: Non-Incumbent",
                              "Republican × Challenger",
                              "Republican × Non-Incumbent"),
          title = "Regression Results: Women Candidates Campaign Finance")
## 
## Regression Results: Women Candidates Campaign Finance
## ============================================================================================
##                                                      Dependent variable:                    
##                                  -----------------------------------------------------------
##                                  Log Receipts Log Individual Contributions Log Disbursements
##                                      (1)                  (2)                     (3)       
## --------------------------------------------------------------------------------------------
## Intercept (Democratic Incumbent)  -6.781***            -7.211***               -7.571***    
##                                    (0.772)              (0.808)                 (0.764)     
##                                                                                             
## Party: Republican                 -6.119***            -5.099***               -6.002***    
##                                    (0.728)              (0.762)                 (0.720)     
##                                                                                             
## Incumbency: Challenger             5.554***             7.038***               6.887***     
##                                    (0.892)              (0.934)                 (0.882)     
##                                                                                             
## Incumbency: Non-Incumbent          5.143***             5.837***               6.526***     
##                                    (1.040)              (1.089)                 (1.029)     
##                                                                                             
## Republican × Challenger           15.366***            13.304***               15.801***    
##                                    (1.229)              (1.287)                 (1.215)     
##                                                                                             
## Republican × Non-Incumbent        -5.586***            -6.053***               -6.016***    
##                                    (0.515)              (0.539)                 (0.509)     
##                                                                                             
## --------------------------------------------------------------------------------------------
## Observations                         519                  519                     519       
## R2                                  0.678                0.631                   0.703      
## Adjusted R2                         0.675                0.627                   0.700      
## Residual Std. Error (df = 513)      5.149                5.390                   5.091      
## F Statistic (df = 5; 513)         216.112***           175.251***             242.582***    
## ============================================================================================
## Note:                                                            *p<0.1; **p<0.05; ***p<0.01
# Create visualizations

# 1. Mean receipts by party and incumbency status
receipts_summary <- women_candidates %>%
  group_by(party, incumbency) %>%
  summarize(
    mean_receipts = mean(receipts, na.rm = TRUE),
    se_receipts = sd(receipts, na.rm = TRUE) / sqrt(n()),
    n = n(),
    .groups = "drop"
  )

# Plot for receipts
plot1 <- ggplot(receipts_summary, aes(x = incumbency, y = mean_receipts, fill = party)) +
  geom_bar(stat = "identity", position = position_dodge()) +
  geom_errorbar(aes(ymin = mean_receipts - se_receipts, 
                    ymax = mean_receipts + se_receipts),
                width = 0.2, position = position_dodge(0.9)) +
  labs(title = "Mean Campaign Receipts by Party and Incumbency Status",
       x = "Incumbency Status",
       y = "Mean Receipts ($)",
       fill = "Party") +
  scale_fill_manual(values = c("Democratic" = "blue", "Republican" = "red")) +
  theme_minimal() +
  scale_y_continuous(labels = scales::comma) +
  theme(legend.position = "bottom")

# 2. Mean contributions by party and incumbency status
contributions_summary <- women_candidates %>%
  group_by(party, incumbency) %>%
  summarize(
    mean_contributions = mean(contributions, na.rm = TRUE),
    se_contributions = sd(contributions, na.rm = TRUE) / sqrt(n()),
    n = n(),
    .groups = "drop"
  )

# Plot for contributions
plot2 <- ggplot(contributions_summary, aes(x = incumbency, y = mean_contributions, fill = party)) +
  geom_bar(stat = "identity", position = position_dodge()) +
  geom_errorbar(aes(ymin = mean_contributions - se_contributions, 
                    ymax = mean_contributions + se_contributions),
                width = 0.2, position = position_dodge(0.9)) +
  labs(title = "Mean Individual Contributions by Party and Incumbency Status",
       x = "Incumbency Status",
       y = "Mean Individual Contributions ($)",
       fill = "Party") +
  scale_fill_manual(values = c("Democratic" = "blue", "Republican" = "red")) +
  theme_minimal() +
  scale_y_continuous(labels = scales::comma) +
  theme(legend.position = "bottom")

# 3. Mean disbursements by party and incumbency status
disbursements_summary <- women_candidates %>%
  group_by(party, incumbency) %>%
  summarize(
    mean_disbursements = mean(disbursements, na.rm = TRUE),
    se_disbursements = sd(disbursements, na.rm = TRUE) / sqrt(n()),
    n = n(),
    .groups = "drop"
  )

# Plot for disbursements
plot3 <- ggplot(disbursements_summary, aes(x = incumbency, y = mean_disbursements, fill = party)) +
  geom_bar(stat = "identity", position = position_dodge()) +
  geom_errorbar(aes(ymin = mean_disbursements - se_disbursements, 
                    ymax = mean_disbursements + se_disbursements),
                width = 0.2, position = position_dodge(0.9)) +
  labs(title = "Mean Campaign Disbursements by Party and Incumbency Status",
       x = "Incumbency Status",
       y = "Mean Disbursements ($)",
       fill = "Party") +
  scale_fill_manual(values = c("Democratic" = "blue", "Republican" = "red")) +
  theme_minimal() +
  scale_y_continuous(labels = scales::comma) +
  theme(legend.position = "bottom")

# 4. Comparing the distribution of campaign finance metrics
data_long <- women_candidates %>%
  pivot_longer(cols = c(receipts, contributions, disbursements),
               names_to = "metric",
               values_to = "value") %>%
  mutate(metric = factor(metric, levels = c("receipts", "contributions", "disbursements"),
                         labels = c("Receipts", "Individual Contributions", "Disbursements")))

# Boxplot for distributions
plot4 <- ggplot(data_long, aes(x = party, y = value, fill = party)) +
  geom_boxplot(alpha = 0.7) +
  facet_grid(incumbency ~ metric, scales = "free_y") +
  labs(title = "Distribution of Campaign Finance Metrics by Party and Incumbency",
       x = "Party",
       y = "Amount ($)",
       fill = "Party") +
  scale_fill_manual(values = c("Democratic" = "blue", "Republican" = "red")) +
  theme_minimal() +
  scale_y_continuous(labels = scales::comma, trans = "log10") +
  theme(legend.position = "bottom")

# 5. Correlation between receipts and contributions
plot5 <- ggplot(women_candidates, aes(x = contributions, y = receipts, color = party, shape = incumbency)) +
  geom_point(alpha = 0.6) +
  geom_smooth(method = "lm", aes(group = interaction(party, incumbency)), se = FALSE) +
  labs(title = "Relationship Between Individual Contributions and Total Receipts",
       x = "Individual Contributions ($)",
       y = "Total Receipts ($)",
       color = "Party",
       shape = "Incumbency Status") +
  scale_color_manual(values = c("Democratic" = "blue", "Republican" = "red")) +
  theme_minimal() +
  scale_x_continuous(labels = scales::comma) +
  scale_y_continuous(labels = scales::comma) +
  theme(legend.position = "bottom")

# Display the plots
print(plot1)

print(plot2)

print(plot3)

print(plot4)

print(plot5)
## `geom_smooth()` using formula = 'y ~ x'

# Additional Analysis - Ratio of contributions to receipts

# Calculate the ratio
women_candidates$contribution_ratio <- women_candidates$contributions / women_candidates$receipts

# Summarize the ratio by party and incumbency
ratio_summary <- women_candidates %>%
  group_by(party, incumbency) %>%
  summarize(
    mean_ratio = mean(contribution_ratio, na.rm = TRUE),
    median_ratio = median(contribution_ratio, na.rm = TRUE),
    sd_ratio = sd(contribution_ratio, na.rm = TRUE),
    se_ratio = sd(contribution_ratio, na.rm = TRUE) / sqrt(n()),
    n = n(),
    .groups = "drop"
  )

# Plot the ratio
plot6 <- ggplot(ratio_summary, aes(x = incumbency, y = mean_ratio, fill = party)) +
  geom_bar(stat = "identity", position = position_dodge()) +
  geom_errorbar(aes(ymin = mean_ratio - se_ratio, 
                    ymax = mean_ratio + se_ratio),
                width = 0.2, position = position_dodge(0.9)) +
  labs(title = "Individual Contributions as a Proportion of Total Receipts",
       subtitle = "By Party and Incumbency Status",
       x = "Incumbency Status",
       y = "Mean Contribution Ratio",
       fill = "Party") +
  scale_fill_manual(values = c("Democratic" = "blue", "Republican" = "red")) +
  theme_minimal() +
  scale_y_continuous(labels = scales::percent) +
  theme(legend.position = "bottom")

print(plot6)

# Summary statistics by party
party_summary <- women_candidates %>%
  group_by(party) %>%
  summarize(
    n = n(),
    mean_receipts = mean(receipts, na.rm = TRUE),
    median_receipts = median(receipts, na.rm = TRUE),
    mean_contrib = mean(contributions, na.rm = TRUE),
    median_contrib = median(contributions, na.rm = TRUE),
    mean_disbursements = mean(disbursements, na.rm = TRUE),
    median_disbursements = median(disbursements, na.rm = TRUE),
    .groups = "drop"
  )

print(party_summary)
## # A tibble: 2 × 8
##   party          n mean_receipts median_receipts mean_contrib median_contrib
##   <chr>      <int>         <dbl>           <dbl>        <dbl>          <dbl>
## 1 Democratic   250          812.       0.000727         5338.      0.000761 
## 2 Republican   269       699734.       0.0000269    18726177.      0.0000165
## # ℹ 2 more variables: mean_disbursements <dbl>, median_disbursements <dbl>
# Summary statistics by incumbency
incumbency_summary <- women_candidates %>%
  group_by(incumbency) %>%
  summarize(
    n = n(),
    mean_receipts = mean(receipts, na.rm = TRUE),
    median_receipts = median(receipts, na.rm = TRUE),
    mean_contrib = mean(contributions, na.rm = TRUE),
    median_contrib = median(contributions, na.rm = TRUE),
    mean_disbursements = mean(disbursements, na.rm = TRUE),
    median_disbursements = median(disbursements, na.rm = TRUE),
    .groups = "drop"
  )

print(incumbency_summary)
## # A tibble: 3 × 8
##   incumbency        n mean_receipts median_receipts  mean_contrib median_contrib
##   <chr>         <int>         <dbl>           <dbl>         <dbl>          <dbl>
## 1 Challenger      220          2.11      0.00000346        0.0660     0.00000675
## 2 Incumbent       180          4.04      0.000244          6.93       0.000130  
## 3 Non-Incumbent   119    1583448.      373.         42341806.        74.1       
## # ℹ 2 more variables: mean_disbursements <dbl>, median_disbursements <dbl>
# Combined summary
combined_summary <- women_candidates %>%
  group_by(party, incumbency) %>%
  summarize(
    n = n(),
    mean_receipts = mean(receipts, na.rm = TRUE),
    median_receipts = median(receipts, na.rm = TRUE),
    mean_contrib = mean(contributions, na.rm = TRUE),
    median_contrib = median(contributions, na.rm = TRUE),
    mean_disbursements = mean(disbursements, na.rm = TRUE),
    median_disbursements = median(disbursements, na.rm = TRUE),
    .groups = "drop"
  )

print(combined_summary)
## # A tibble: 6 × 9
##   party      incumbency        n mean_receipts median_receipts  mean_contrib
##   <chr>      <chr>         <int>         <dbl>           <dbl>         <dbl>
## 1 Democratic Challenger      100       4.60         0.00000440        0.0982
## 2 Democratic Incumbent       100       7.27         0.00322          12.4   
## 3 Democratic Non-Incumbent    50    4034.           0.315         26667.    
## 4 Republican Challenger      120       0.0330       0.00000237        0.0392
## 5 Republican Incumbent        80       0.00699      0.00000283        0.0353
## 6 Republican Non-Incumbent    69 2727950.        6012.         73004950.    
## # ℹ 3 more variables: median_contrib <dbl>, mean_disbursements <dbl>,
## #   median_disbursements <dbl>
# Interpretation of the results
cat("\n--- Key Findings from Women Candidates Campaign Finance Analysis ---\n\n")
## 
## --- Key Findings from Women Candidates Campaign Finance Analysis ---
cat("1. Party Differences:\n")
## 1. Party Differences:
cat("   - Democratic women candidates have higher mean receipts compared to Republican women across all incumbency types.\n")
##    - Democratic women candidates have higher mean receipts compared to Republican women across all incumbency types.
cat("   - The gap is especially pronounced for challengers and non-incumbents.\n\n")
##    - The gap is especially pronounced for challengers and non-incumbents.
cat("2. Incumbency Effects:\n")
## 2. Incumbency Effects:
cat("   - For both parties, incumbents generally have higher receipts than challengers.\n")
##    - For both parties, incumbents generally have higher receipts than challengers.
cat("   - Non-incumbent candidates (open seats) show large variability in fundraising success.\n\n")
##    - Non-incumbent candidates (open seats) show large variability in fundraising success.
cat("3. Interaction Effects:\n")
## 3. Interaction Effects:
cat("   - Republican women in non-incumbent races show a distinctive pattern in their fundraising compared to Democratic women.\n")
##    - Republican women in non-incumbent races show a distinctive pattern in their fundraising compared to Democratic women.
cat("   - The interaction between party and incumbency status is statistically significant, indicating that the effect of incumbency differs by party.\n\n")
##    - The interaction between party and incumbency status is statistically significant, indicating that the effect of incumbency differs by party.
cat("4. Individual Contributions:\n")
## 4. Individual Contributions:
cat("   - Democratic women generally receive a higher proportion of their funds from individual contributors compared to Republican women.\n")
##    - Democratic women generally receive a higher proportion of their funds from individual contributors compared to Republican women.
cat("   - Challenger candidates are more reliant on individual contributions than incumbents.\n\n")
##    - Challenger candidates are more reliant on individual contributions than incumbents.
cat("5. Disbursements:\n")
## 5. Disbursements:
cat("   - Spending patterns closely follow receipt patterns, suggesting candidates spend in proportion to what they raise.\n")
##    - Spending patterns closely follow receipt patterns, suggesting candidates spend in proportion to what they raise.
cat("   - There are no significant differences in spending efficiency between parties.\n\n")
##    - There are no significant differences in spending efficiency between parties.
cat("These findings suggest important differences in campaign finance patterns between Democratic and Republican women candidates, with implications for understanding gender and party dynamics in electoral politics.\n")
## These findings suggest important differences in campaign finance patterns between Democratic and Republican women candidates, with implications for understanding gender and party dynamics in electoral politics.