I have a dataset where I have different institutional investors for each year. In this particular example, I want to generate new variables for each perc variable and take its value as long as DED_count >=1. In the current form, I have summed all the perc values for all pclass where it is DED. Below is an example of the data. For example, when DED_count is 2, I want to generate two new variables that take the value of the corresponding perc. I also want to do the same regardless of what DED_count is (i.e., not be fixated on the current dataset example).
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str8 cusip float yr str28 stkname double mgrno float perc str3 pclass float(DED DED_count) "00036020" 1999 "AAON INC" 8208 .17496246 "DED" .17496246 1 "00040010" 2002 "ABC BANCORP" 40175 .01251549 "DED" .01251549 1 "00040010" 2003 "ABC BANCORP" 40175 .028855886 "DED" .028855886 1 "00040010" 2004 "ABC BANCORP" 40175 .028873594 "DED" .028873594 1 "00080S10" 2005 "ABX AIR INC" 6197 .01274526 "DED" .01274526 1 "00080S10" 2006 "ABX AIR INC" 6197 .012770413 "DED" .012770413 1 "00081T10" 2005 "ACCO BRANDS CORP" 4690 .06530727 "DED" .06530727 1 "00081T10" 2006 "ACCO BRANDS CORP" 4690 .13980632 "DED" .13980632 1 "00081T10" 2007 "ACCO BRANDS CORP" 4690 .13906701 "DED" .13906701 1 "00083310" 2006 "ACA CAPITAL HOLDINGS INC" 24230 .12620589 "DED" .12620589 1 "00083310" 2007 "ACA CAPITAL HOLDINGS INC" 24230 .13225694 "DED" .13225694 1 "00086T10" 2005 "A C MOORE ARTS & CRAFTS INC" 6890 .09173632 "DED" .09173632 1 "00086T10" 2007 "A C MOORE ARTS & CRAFTS INC" 8200 .11097958 "DED" .11097958 1 "00087B10" 2005 "ACR GROUP INC" 40175 .017478079 "DED" .017478079 1 "00088610" 1999 "A D C TELECOMMUNICATIONS" 81120 .07934304 "DED" .07934304 1 "00088610" 2000 "A D C TELECOMMUNICATIONS" 81120 .04455973 "DED" .04455973 1 "00088610" 2001 "A D C TELECOMMUNICATIONS" 81120 .04358229 "DED" .04358229 1 "00088610" 2002 "A D C TELECOMMUNICATIONS" 81120 .04323986 "DED" .04323986 1 "00088610" 2003 "A D C TELECOMMUNICATIONS" 81120 .04279369 "DED" .04279369 1 "00088630" 2007 "A D C TELECOMMUNICATIONS" 81120 .0393004 "DED" .0393004 1 "00088630" 2008 "A D C TELECOMMUNICATIONS" 81120 .04791253 "DED" .04791253 1 "00088630" 2009 "A D C TELECOMMUNICATIONS" 81120 .010849047 "DED" .010849047 1 "00088U10" 2005 "A D A M INC" 10470 .020652024 "DED" .020652024 1 "00088U10" 2006 "A D A M INC" 10470 .018231692 "DED" .018231692 1 "00089910" 2014 "ADMA BIOLOGICS INC" 13952 .3883094 "DED" .4301942 2 "00089910" 2014 "ADMA BIOLOGICS INC" 12843 .04188474 "DED" .4301942 2 "00089910" 2015 "ADMA BIOLOGICS INC" 12843 .09000215 "DED" .4268052 2 "00089910" 2015 "ADMA BIOLOGICS INC" 13952 .33680305 "DED" .4268052 2 "00089910" 2016 "ADMA BIOLOGICS INC" 13952 .27998534 "DED" .3663742 2 "00089910" 2016 "ADMA BIOLOGICS INC" 12843 .08638884 "DED" .3663742 2 "00089910" 2017 "ADMA BIOLOGICS INC" 12843 .030012254 "DED" .12826061 2 "00089910" 2017 "ADMA BIOLOGICS INC" 13952 .09824836 "DED" .12826061 2 "00089910" 2018 "ADMA BIOLOGICS INC" 13952 .07784452 "DED" .16902006 2 "00089910" 2018 "ADMA BIOLOGICS INC" 12843 .09117553 "DED" .16902006 2 "00089C10" 1999 "ADE CORP MASS" 71520 .18399276 "DED" .18399276 1 "00089C10" 2000 "ADE CORP MASS" 71520 .21833213 "DED" .21833213 1 "00089C10" 2001 "ADE CORP MASS" 71520 .27663425 "DED" .27663425 1 "00089C10" 2002 "ADE CORP MASS" 71520 .26340744 "DED" .26340744 1 "00089C10" 2003 "ADE CORP MASS" 71520 .25099626 "DED" .25099626 1 "00089C10" 2004 "ADE CORP MASS" 71520 .24046846 "DED" .24046846 1 "00089C10" 2005 "ADE CORP MASS" 71520 .1814822 "DED" .1814822 1 "00094410" 1999 "AER ENERGY RES INC" 66150 .08760785 "DED" .08760785 1 "00095510" 2000 "ACT TELECONFERENCING INC" 180 .07064641 "DED" .07064641 1 "00095510" 2001 "ACT TELECONFERENCING INC" 180 .0912797 "DED" .0912797 1 "00095710" 1999 "ABM INDS INC" 41000 .07707524 "DED" .07707524 1 "00095710" 2000 "ABM INDS INC" 41000 .07677729 "DED" .07677729 1 "00095710" 2005 "ABM INDS INC" 40175 .010751123 "DED" .010751123 1 "00095710" 2008 "ABM INDS INC" 12080 .012167297 "DED" .012167297 1 "00095710" 2009 "ABM INDS INC" 12080 .01266786 "DED" .01266786 1 "00095710" 2010 "ABM INDS INC" 12080 .01240789 "DED" .01240789 1 "00095710" 2013 "ABM INDUSTRIES INC" 24230 .01870888 "DED" .01870888 1 "00095710" 2017 "ABM INDUSTRIES INC" 50090 .06900246 "DED" .06900246 1 "00097510" 1999 "ACT NETWORKS INC" 24230 .03045175 "DED" .03045175 1 "00103110" 2007 "AEP INDS INC" 11482 .016744526 "DED" .016744526 1 "00103110" 2008 "AEP INDS INC" 11482 .0934154 "DED" .0934154 1 "00104Q10" 2002 "AFC ENTERPRISES INC" 12740 .02464355 "DED" .02464355 1 "00104Q10" 2004 "AFC ENTERPRISES INC" 42315 .04976957 "DED" .04976957 1 "00104Q10" 2010 "AFC ENTERPRISES INC" 11828 .011575295 "DED" .011575295 1 "00105510" 2006 "AFLAC INC" 12740 .02310598 "DED" .02310598 1 "00105510" 2007 "AFLAC INC" 12740 .03275422 "DED" .03275422 1 "00108410" 2003 "AGCO CORP" 39580 .01380504 "DED" .01380504 1 "00108410" 2004 "AGCO CORP" 12740 .017774284 "DED" .017774284 1 "00108410" 2005 "AGCO CORP" 12740 .029665885 "DED" .029665885 1 "00108410" 2014 "AGCO CORP" 24230 .020137087 "DED" .020137087 1 "00108410" 2015 "AGCO CORP" 24230 .016534004 "DED" .016534004 1 "00119010" 2010 "AGIC CONV & INCOME FD" 18100 .017297624 "DED" .017297624 1 "00120410" 1999 "AGL RES INC" 39580 .021316243 "DED" .021316243 1 "00120410" 2000 "AGL RES INC" 39580 .023940023 "DED" .023940023 1 "00120410" 2001 "AGL RES INC" 39580 .02639016 "DED" .02639016 1 "00120410" 2002 "AGL RES INC" 39580 .023651626 "DED" .023651626 1 "00120410" 2003 "AGL RES INC" 39580 .01447708 "DED" .01447708 1 "00120410" 2004 "AGL RES INC" 12740 .028022043 "DED" .028022043 1 "00128210" 2008 "A H BELO CORP" 10513 .010853278 "DED" .010853278 1 "00128210" 2009 "A H BELO CORP" 10513 .01065781 "DED" .01065781 1 "00129610" 1999 "AHL SVCS INC" 12740 .028725727 "DED" .028725727 1 "00130H10" 2001 "AES CORP" 12740 .01021433 "DED" .01021433 1 "00154710" 2003 "AK STL HLDG CORP" 40175 .06273455 "DED" .06273455 1 "00154710" 2004 "AK STL HLDG CORP" 40175 .0993427 "DED" .0993427 1 "00154710" 2005 "AK STL HLDG CORP" 40175 .09950276 "DED" .09950276 1 "00154710" 2006 "AK STL HLDG CORP" 40175 .09936154 "DED" .09936154 1 "00154710" 2007 "AK STL HLDG CORP" 4430 .01944233 "DED" .0815079 2 "00154710" 2007 "AK STL HLDG CORP" 40175 .06206558 "DED" .0815079 2 "00160010" 2012 "ALCO STORES INC" 180 .1824159 "DED" .1824159 1 "00162Q10" 2016 "ALPS ETF TR" 9082 .02177737 "DED" .02177737 1 "00162Q10" 2017 "ALPS ETF TR" 9082 .05580965 "DED" .05580965 1 "00162Q10" 2018 "COHEN STEERS GLOBAL REALTY M" 9082 .020408 "DED" .020408 1 "00162Q45" 2018 "ALERIAN MLP" 12684 .03034888 "DED" .03034888 1 "00163T10" 1999 "AMB PROPERTY CORP" 12740 .04764545 "DED" .1337269 3 "00163T10" 1999 "AMB PROPERTY CORP" 81945 .02494858 "DED" .1337269 3 "00163T10" 1999 "AMB PROPERTY CORP" 18100 .06113286 "DED" .1337269 3 "00163T10" 2000 "AMB PROPERTY CORP" 12740 .04902019 "DED" .12748228 2 "00163T10" 2000 "AMB PROPERTY CORP" 18100 .0784621 "DED" .12748228 2 "00163T10" 2001 "AMB PROPERTY CORP" 18100 .08670127 "DED" .116807 2 "00163T10" 2001 "AMB PROPERTY CORP" 12740 .03010573 "DED" .116807 2 "00163T10" 2002 "AMB PROPERTY CORP" 12740 .03049186 "DED" .03049186 1 "00163T10" 2003 "AMB PROPERTY CORP" 18100 .02376509 "DED" .06315492 2 "00163T10" 2003 "AMB PROPERTY CORP" 12740 .03938983 "DED" .06315492 2 "00163T10" 2004 "AMB PROPERTY CORP" 18100 .036586836 "DED" .08806798 2 "00163T10" 2004 "AMB PROPERTY CORP" 12740 .05148114 "DED" .08806798 2 "00163T10" 2005 "AMB PROPERTY CORP" 12740 .031302657 "DED" .06633562 2 end
I really appreciate your help!
Stata 16.1
0 Response to Creating different variables for firm-year
Post a Comment