<>
Here is an example code, maybe you can clarify your request with it...
*************
clear*
set obs 100
gen stock=_n
gen numofshares=100000+int(10000*runiform())
gen shareprice=50+int(10*runiform())
//expand to # of months
expand 12
bys stock: replace shareprice=shareprice+rnormal(0,3)
//get time period (after expansion!)
bys stock: gen month=_n
gen marketcap=numofshares*shareprice
compress
bys month: egen rank=rank(marketcap)
//example for second month
gen byte topportfolio = rank<=10 & month==2
gen byte bottomportfolio = rank>=90 & month==2
bys stock (month): gen return=shareprice[_n]/shareprice[_n-1]-1
//portfolio top 10% market cap
//for second month of sample period
summ return if topportfolio, detail
//bottom 10% for second month
//in terms of market cap
summ return if bottomportfolio, detail
*************
HTH
Martin
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of qing ye
Sent: Samstag, 14. November 2009 13:08
To: [email protected]
Subject: st: stata and portfolios
Deal all,
I am wondering whether I can write code in stata to do portfolios analysis.
By portfolio analysis, I mean
1. I want to sort stocks based on some criteria (e.g. market
capitalization) on some dates (e.g. every month over the sample
period)
2. construct serval portfolios based on the ranking of this variable (
top 10%, 20%, bottom 10% etc).
3. calculate the return and summary statistics for each portfolio.
4. maybe run some regression (e.g. CAPM) using the portfolio returns etc
5. get the results reported out
Can stata do such analysis? where I can get more information on how to
write such code, is there any template code that I can study on?
Thanks for your help!
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/