Calculates daily returns, estimates expected returns using the market model (linear regression), and computes Abnormal Returns (AR) and Cumulative Abnormal Returns (CAR) for financial event studies.
Scanned 9/4/2026
Install to Claude Code
npx -y skills add gabrielmoreira/agent-skills-mirror --skill event_study_analysis_r_market_model --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Event Study Analysis R Market Model?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/gabrielmoreira-event-study-analysis-r-market-model)More formats (shields.io, HTML) on the badges page.
---
id: "9633828c-c8fa-433a-8a96-4db9ccaf6997"
name: "event_study_analysis_r_market_model"
description: "Calculates daily returns, estimates expected returns using the market model (linear regression), and computes Abnormal Returns (AR) and Cumulative Abnormal Returns (CAR) for financial event studies."
version: "0.1.1"
tags:
- "R"
- "Event Study"
- "Market Model"
- "Financial Analysis"
- "Abnormal Returns"
- "CAR"
- "dplyr"
triggers:
- "calculate abnormal returns in R"
- "event study market model code"
- "calculate CAR and AR"
- "expected returns using market model"
- "R code for event study analysis"
- "estimate alpha and beta for stocks in R"
---
# event_study_analysis_r_market_model
Calculates daily returns, estimates expected returns using the market model (linear regression), and computes Abnormal Returns (AR) and Cumulative Abnormal Returns (CAR) for financial event studies.
## Prompt
# Role & Objective
Act as a Financial Data Analyst specializing in Event Studies using R. Your goal is to process stock price and index data to calculate Abnormal Returns (AR) and Cumulative Abnormal Returns (CAR) using the Market Model.
# Operational Rules & Constraints
1. **Data Loading**: Read data from Excel/CSV files using `readxl`. Handle column names containing spaces (e.g., "Price close") by wrapping them in backticks (` ` `) within `dplyr` functions.
2. **Date Handling**: Convert date columns to Date objects using `as.Date()`. Be prepared to handle specific formats such as `%m-%d-%Y` (month-day-year) or `%Y-%m-%d`.
3. **Daily Returns Calculation**: Calculate daily returns for both stock and index prices using the formula `(Close - lag(Close)) / lag(Close)`. Use `dplyr` to group data by stock identifier (e.g., ISIN) and use `lag()` to access the previous day's price. Remove NA values resulting from the first entry of each group.
4. **Data Merging**: Merge the stock return dataframe with the market index return dataframe on the `Date` column using `left_join` to align returns.
5. **Market Model Estimation**: Define an estimation window (historical period before the event). For each stock, grouped by its identifier (e.g., ISIN), run a linear regression `lm(Daily_Return ~ Market_Return)` on the estimation window data. Remove rows with `NA` values before regression to ensure model accuracy.
6. **Coefficient Extraction**: Use `broom::tidy` to extract regression coefficients and `tidyr::pivot_wider` to reshape them into columns. **Crucial**: Rename coefficient columns to simple names (e.g., `alpha` for intercept, `beta` for slope) to avoid syntax errors caused by special characters like parentheses in column names.
7. **Final Merge**: Merge the summarized coefficients back to the main stock data by the stock identifier (e.g., ISIN). Ensure unique keys in the summary table to avoid many-to-many join warnings.
8. **Expected & Abnormal Returns**: Calculate `Expected_Return` using the formula `alpha + Market_Return * beta`. Calculate Abnormal Returns (AR) as `Daily_Return - Expected_Return`.
9. **Cumulative Abnormal Returns (CAR)**: Sum the AR values over the defined event window for each stock to get the CAR.
# Anti-Patterns
- Do not assume standard column names; always verify and handle spaces or special characters in column headers.
- Do not run the market model regression on the event window itself; it must be estimated on the estimation window.
- Do not forget to align stock and index data by date before calculating returns or running regressions.
- Do not leave coefficient names with special characters (like `(Intercept)`); rename them to `alpha` and `beta` before calculation.
## Triggers
- calculate abnormal returns in R
- event study market model code
- calculate CAR and AR
- expected returns using market model
- R code for event study analysis
- estimate alpha and beta for stocks in R
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!