Hi. I need help to form rank and portfolio by following the procedure below (step 1 to 3). The code I used to do this, I mentioned in the following but I did not get the similar result like the paper I am trying to replicate. Please suggest me whether my codes are right or wrong. The authors rank leverage and form portfolio, and track their portfolio in the following 20 years.


Step 1: Each calendar year, we sort firms into quartiles (i.e., four portfolios) according to their leverage ratios, which we denote: Very High, High, Medium, and Low. The portfolio formation year is denoted event year 0. We then compute the average leverage for each portfolio in each of the subsequent 20 years, holding the portfolio composition constant.

Step2: We repeat these two steps of sorting and averaging for every year in the sample period. This process generates 39 sets of event-time averages, one for each calendar year in our sample.

Step3: We then compute the average leverage of each portfolio across the 39 sets within each event year. The figure represents the average leverage along the event time. Here the event time refer to the x-th year after portfolio formation.

39 = 39 times of portfolio formations, i.e., each year during 1965 and 2003, the authors rank leverage and form portfolio, and track their portfolio in the following 20 years.



/* create rank and four portfolio quartiles of book_leverage */

egen portfolio_bk_lev=xtile(book_leverage), n(4) by(fyear)



**gen average leverage ratio based on four portfolio:

tabstat book_leverage if portfolio_bk_lev==4 , by( fyear ) stat(n mean median)

tabstat book_leverage if portfolio_bk_lev==3 , by( fyear ) stat(n mean median)

tabstat book_leverage if portfolio_bk_lev==2 , by( fyear ) stat(n mean median)

tabstat book_leverage if portfolio_bk_lev==1 , by( fyear ) stat(n mean median)

Please advice me how to do that. Any suggestion much appreciated. Thank you.