Dear Stata users
My data is in panel format, sorted by date. For each day stocks are assigned a portfolio. For example on 03/15/2004 there only 3 stocks in the portfolio with respective ids of 73,74,75.
I need to sort them further based on TVN into two portfolios with High and Low TVN.
I use the following code:
However, it assigns a portfolio based on TVN for all available stocks rather than those which are in a portfolio. It creates bias for stocks in a portfolio.
How should I fix it so the p_winner appears only for stocks 73,74,75?
Thank you.
My data is in panel format, sorted by date. For each day stocks are assigned a portfolio. For example on 03/15/2004 there only 3 stocks in the portfolio with respective ids of 73,74,75.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float date str12 IssueCode float p_winner byte stock_id_long double TVN 16145 "KR7003601002" 2 73 16.22814687509245 16145 "KR7007190002" 2 74 36.49090305762375 16145 "KR7007050008" 1 75 .1385657756472274 16145 "KR7009830001" 2 . 4.010736934867263 16145 "KR7016590002" 2 . 1.0417176309731364 16145 "KR7006980007" 2 . 1.198009268161519 16145 "KR7051911006" 2 . 1.153283370665912 end format %tdNN/DD/CCYY date
I use the following code:
egen p_winner = xtile(TVN), nquantiles (2) by( stock_id_long )
How should I fix it so the p_winner appears only for stocks 73,74,75?
Thank you.

Comment