
_files/640_004.jpg)
You should make sure the dataset has been saved under a different name before dropping anyĪt this point you can also drop some variables you won't need any longer: count_event_obs and count_est_obs. Observations within the event and estimation windows, as well as the total number of observations for The "tab" will produce a list of company_ids that do not have enough You can now determine which companies do not have a Finally, we replace all the missing values with zeroes, creating aĭummy variable. That counts how many observations, within each company_id, has a 1 assigned to First we create a variable that equals 1 if the observation is
EGEN STATA WINDOWS
The procedure for determining the event and estimation windows is the Replace estimation_window=0 if estimation_window=. (You can of course change these numbers to suit your analysis.)īy company_id: gen event_window=1 if dif>=-2 & dif=-60Įgen count_est_obs=count(estimation_window), by(company_id) Window) and 30 days for the estimation window. Let's say we want 2ĭays before and after the event date (a total of 5 days in the event Need to make sure that we have the minimum number of observations beforeĪnd after the event date, as well as the minimum number of observationsīefore the event window for the estimation window. That counts the number of days between each individual observation and the event day. Finally, we simply take the difference between the two, creating a variable, dif, We create a variable with theĮvent date's day number on all of the observations within thatĬompany_id. We determine which observation occurs on the event date. Variable that counts the number of days within each company_id. For trading days, we first need to create a This can be either calendar days or trading days.īy company_id: gen target=datenum if date=event_dateĪs you can see, calculating the number of trading days is a little To do this, you will need to createĪ variable, dif, that will count the number of days from the observation to theĮvent date. You can continue, you must make sure that you will be conducting yourĪnalyses on the correct observations. It's also possible that you do not have enough for some. It's likely that you have more observations for each company than you Cleaning the data and Calculating the Event and Estimation Windows Your task will be much easier if you enter the commands in a do file, which is a text file containing a list of Stata commands. If you need assistance with Stata commands, you can find out more about it here. We also assume that you have a basic familiarity with Stata. If you need to prepare your data or want to try out the commands with our sample data, go to data preparation page. We assume that you already have data with a date variable, which we call "date", and a company identifier, which we have called "company_id". This document is designed to help you conduct event studies using Stata. Calculating Abnormal and Cumulative Abnormal Returns.Cleaning the Data and Calculating the Event Window.The above command states that within each stockid group (that has been sorted by ascending order of year), all ticker observations except the first are to be replaced with the value from the first year.An event study is used to examine reactions of the market to events of interest.Ī simple event study involves the following steps: We can automate the process using by and _n.īysort stockid (year): replace ticker=ticker if _n>1


To fill in rows 6 through 10 with "AMZN", you could do this:Ĭlearly, with multiple observations to replace, replacing values line-by-line this way becomes cumbersome and prone to human error. To fill in row 6 of ticker with the appropriate value ("AMZN"), you could do this: We will fill in the blanks in the ticker variable (this assumes that the ticker symbols for these stocks did not change over time).įirst, make sure that the data are sorted by stockid and year. Now that you have a sense of what _n and _N do, let's use _n in combination with by to perform a concrete task.
