论文事件研究:如何将处理后的数据转换为eventstudie包所需zoo对象?
eventstudie Package Got it, let's walk through exactly how to convert your processed data into zoo objects for your event study—this is a straightforward but critical step to get right for the eventstudie package. I'll break it down for both your return data and event data.
Step 1: Convert Return Data (db.kurs) to Zoo
Your db.kurs is a tibble/data.frame, which is easy to convert to a zoo object since zoo relies on a time index paired with your data values.
First, make sure you have the zoo package loaded. Then, you'll need to specify two things:
- The return values (your core data)
- The date index (must be a
Dateformat column indb.kurs)
Here's the code—just replace the column names with the actual ones from your data (I used placeholders like return and date since you didn't specify exact column names):
# Load required package library(zoo) # Convert tibble/data.frame to zoo object db_zoo <- zoo( x = db.kurs$return, # Replace with your actual return column name order.by = db.kurs$date # Replace with your actual Date column name ) # Optional: Verify the structure to make sure it worked str(db_zoo)
Quick Check:
If your date column isn't already in Date format, convert it first with:
db.kurs$date <- as.Date(db.kurs$date)
Step 2: Convert Event Data to Zoo
Your event data is a 9-row data.frame with when (Date) and name (all "Deutsche Bank"). For event studies, we usually want a zoo object that marks when events occur for your target firm.
Since all events are for the same company, you can create a zoo object where the index is the event dates, and the value can either be the company name or a simple marker (like 1) to flag event days:
# Convert event data to zoo object events_zoo <- zoo( x = events$name, # Or use rep(1, nrow(events)) to mark event occurrences order.by = events$when ) # Verify str(events_zoo)
Key Notes for eventstudie Package
- Make sure your return data zoo object covers the entire estimation window and event window for each event. If an event date isn't present in your return data, the package might throw an error.
- For single-firm event studies (like yours, all events are for Deutsche Bank), the
eventstudiepackage will work smoothly with these zoo objects. You can passdb_zooas the return series andevents_zoo(or even the original data.frame, if preferred) as the event data.
内容的提问来源于stack exchange,提问作者N.Messers

