I am hoping to produce a table which counts the number of fund ID’s (ie an ID is distinct to each fund) for different characteristics at the end of each year (ie the latest observed date for each year).
I can count how many of each characteristic (eg how many funds where retail_fund=="Y") following an approach set out in
Cox, N. J. (2007). Speaking Stata: Counting groups, especially panels. The Stata Journal, 7(4), 571-581.
Here is a simple example
I intend saving each of the counts and then displaying them in a suitable table.
However, I am having trouble counting the number of fund ID’s at the end of each year (and for each characteristic – eg if retail_fund == “Y”)
I begin by producing a year() variable but am confused on how to set up the "by id (month): gen byte tag = _n == 1" command to count the last month for each ID in each year.
Thank you very much, Dan
I can count how many of each characteristic (eg how many funds where retail_fund=="Y") following an approach set out in
Cox, N. J. (2007). Speaking Stata: Counting groups, especially panels. The Stata Journal, 7(4), 571-581.
Here is a simple example
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long id float(month ff) str1 retail_fund 2708 665 -.00494564 "N" 2708 666 -.009506066 "N" 2708 679 -.006455688 "N" 2708 680 -.009019009 "N" 2724 666 -.0045031635 "N" 2724 667 -.009472995 "N" 2724 684 -.0017794066 "N" 2724 685 -.003388667 "N" 2745 667 -.0045014257 "Y" 2745 668 -.0032780494 "Y" 2745 696 -.06255567 "Y" 2745 697 -.01358385 "Y" end format %tmCCYY_Mon month
Code:
by id (month): gen byte tag = _n == 1 count if tag count if retail_fund=="Y" & tag
However, I am having trouble counting the number of fund ID’s at the end of each year (and for each characteristic – eg if retail_fund == “Y”)
I begin by producing a year() variable but am confused on how to set up the "by id (month): gen byte tag = _n == 1" command to count the last month for each ID in each year.
Thank you very much, Dan
Comment