Dear Stata Experts,
I am using the following command:
---
sort YMD
foreach X of varlist MktCap* {
by YMD: egen p10_`X'= pctile(`X'), p(10.0)
by YMD: egen p20_`X'= pctile(`X'), p(20.0)
by YMD: egen p30_`X'= pctile(`X'), p(30.0)
by YMD: egen p40_`X'= pctile(`X'), p(40.0)
by YMD: egen p50_`X'= pctile(`X'), p(50.0)
by YMD: egen p60_`X'= pctile(`X'), p(60.0)
by YMD: egen p70_`X'= pctile(`X'), p(70.0)
by YMD: egen p80_`X'= pctile(`X'), p(80.0)
by YMD: egen p90_`X'= pctile(`X'), p(90.0)
---
in Stata 13 on Windows in order to build 10 decile portfolios. YMD is the referring time variable and MktCap stands for market capitalization.
My dataset is from CRSP and contains US stock data from 1963-2016. My goal is to create 10 portfolios. Portfolio 1 shall contain the stocks with the lowest market capitalization and portfolio 10 the ones with the highest market capitalization. Every year in June, I want to repeat the portfolio building. Unfortunately, my formula 1. is not complete, since I don't know exactly how to implement the request to only repeat the portfolio building in June in each year. 2. an error appears saying "invalid 'p' " after creating portfolio 4 when I use this formula.
The relevant variables (columns) looks like:
VMD MktCap
166301 5.434
166301 4.434
166301 3.494
166302 3.494
166302 3.494
166303 3.494
166303 3.494
166304 3.494
Thank your for your help.
Best,
Guest
I am using the following command:
---
sort YMD
foreach X of varlist MktCap* {
by YMD: egen p10_`X'= pctile(`X'), p(10.0)
by YMD: egen p20_`X'= pctile(`X'), p(20.0)
by YMD: egen p30_`X'= pctile(`X'), p(30.0)
by YMD: egen p40_`X'= pctile(`X'), p(40.0)
by YMD: egen p50_`X'= pctile(`X'), p(50.0)
by YMD: egen p60_`X'= pctile(`X'), p(60.0)
by YMD: egen p70_`X'= pctile(`X'), p(70.0)
by YMD: egen p80_`X'= pctile(`X'), p(80.0)
by YMD: egen p90_`X'= pctile(`X'), p(90.0)
---
in Stata 13 on Windows in order to build 10 decile portfolios. YMD is the referring time variable and MktCap stands for market capitalization.
My dataset is from CRSP and contains US stock data from 1963-2016. My goal is to create 10 portfolios. Portfolio 1 shall contain the stocks with the lowest market capitalization and portfolio 10 the ones with the highest market capitalization. Every year in June, I want to repeat the portfolio building. Unfortunately, my formula 1. is not complete, since I don't know exactly how to implement the request to only repeat the portfolio building in June in each year. 2. an error appears saying "invalid 'p' " after creating portfolio 4 when I use this formula.
The relevant variables (columns) looks like:
VMD MktCap
166301 5.434
166301 4.434
166301 3.494
166302 3.494
166302 3.494
166303 3.494
166303 3.494
166304 3.494
Thank your for your help.
Best,
Guest
Comment