Hello all,

I have an unbalanced panel data set on funds and their respective 3 Factor alphas for each year. Moreover, I have their market segments based on their Objective Codes and their Management name. I need to construct the segment rank of a fund by ordering all funds belonging to a specific market segment (crsp_obj_cd) in a given year according to the 3 Factor alpha and rank them with a normalized value from 0 to 1 (best fund). Also, I need to order funds belonging to a specific family (mgmt_id) and assign to them a normalized rank according to the specified Segment rank.

Lastly, I need to perform a piecewise linear regression by estimating the slope coefficients for the bottom quintile, the 3 middle and the top quintile of segment and family ranks. The variables are as follows:

LOW(FamRank)i,t−1=min(FamRanki,t−1, 0.2)
LOW(SegRank)i,t−1=min(SegRanki,t−1, 0.2)
MID(FamRank)i,t−1=min(FamRanki,t−1 − LOW(FamRank)i,t−1, 0.6)
MID(SegRank)i,t−1=min(SegRanki,t−1 − LOW(SegRank)i,t−1, 0.6)
TOP(FamRank)i,t−1=FamRanki,t−1 − (LOW(FamRank)i,t−1 +MID(FamRank)i,t−1)
TOP(SegRank)i,t−1=SegRanki,t−1 − (LOW(SegRank)i,t−1 +MID(SegRank)i,t−1).

Any help is highly appreciated.

A sample of my dataset is given below:
Array