I am attempting to calculate an average (mean) across observations which have common characteristics. It is an element of an event study looking at fund flows and I am using Stata 15.
Specifically, I am averaging “ff” where the variables with common stub “event” are -2, -1, 0, 1 or 2. The result should be a list of the average “ff” for
The data file is as follows
Code:
* Examples generated by -dataex-. To install: ssc install dataex
clear
input long id float(month ff event_1 event_2)
2708 657     -.005559 -1 -3
2708 658 -.0023612394 0 -2
2708 659  .0009129993 1 -1
2708 660 -.0016764477 2 0
2708 661 -.0025546604 3 1
2709 657     -.005559 -1 -3
2709 658 -.0023612394 0 -2
2709 659  .0009129993 1 -1
2709 660 -.0016764477 2 0
2709 661 -.0025546604 3 1
end
format %tmCCYY_Mon month
The result should look like
Code:
clear
input float (diff ave_ff)
-2 -0.0025
-1 -0.00025
0 -0.0035
1 0.0005
2 -0.0045
end
The “diff” variable being the required range from the variables with event stubs (event*).
My initial plan of attack is to (1) sort by the variables with event stubs (event*),
(2) produce new observations from each of the event* variables,
(3) sort by the variables with event stubs (event*),
(4) remove observations with event* outside the -2 to 2 range,
(5) collapse to averages for each
But pls indicate if you think there is a more efficient/precise approach. Thank you, Dan