PE by Revenue

Category : Uncategorized

PE by Revenue

Please make sure you have the most updated mfd_dm, mfd_ta and mfd_tex packages for Stata installed for this post.

*
net from "http://www.researchforprofit.com/stata/mfd_dm"
net from "http://www.researchforprofit.com/stata/mfd_ta"
net from "http://www.researchforprofit.com/stata/mfd_tex"
* click on the blue mfd_dm package and then "click here to install" 
*
*
clear all
cd "/Users/mfd/Desktop"

* Get the components of S&P500 Index
mfd_dm_components_cnn sp500
drop if Symbol==""
sort Symbol
levelsof Symbol, local(tickers)

mfd_dm_EPS `tickers', item(eps) annual pe price
sort date
save data_eps.dta, replace

mfd_dm_EPS `tickers', item(revenue) annual price
sort date
save data_revenue.dta, replace

use data_eps.dta, clear
merge date using data_revenue.dta
drop _merge
sort date
gen day=_n
tsset day
save data_dji.dta, replace

* PE and revenues
clear all
cd "/Users/mfd/Desktop"
use data_dji.dta, clear
keep date PE_*_annual revenue_*_annual
keep if _n==_N
xpose, clear varname
drop if _n==1

gen PE_annual=v1 if strpos(_varname,"PE")
gen revenue_annual=v1 if strpos(_varname,"revenue")

replace _varname=subinstr(_varname,"PE_","",.)
replace _varname=subinstr(_varname,"revenue_","",.)
replace _varname=subinstr(_varname,"_annual","",.)
drop v1
rename _varname symbol
sort symbol
replace PE_annual=PE_annual[_n-1] if (PE_annual==.) & (symbol==symbol[_n-1])
replace PE_annual=PE_annual[_n+1] if (PE_annual==.) & (symbol==symbol[_n+1])

replace revenue_annual=revenue_annual[_n-1] if (revenue_annual==.) & (symbol==symbol[_n-1])
replace revenue_annual=revenue_annual[_n+1] if (revenue_annual==.) & (symbol==symbol[_n+1])
duplicates drop

drop if PE_annual==.
drop if revenue_annual==.

drop if PE_annual>100
drop if PE_annual<-100

replace revenue_annual=revenue_annual/1000000000
twoway (scatter PE_annual revenue_annual if symbol!="AAPL", mlabel(symbol)) (scatter PE_annual revenue_annual if symbol=="AAPL", mlabel(symbol)), ylabel(#30, angle(horizontal)) xlabel(#50, angle(vertical)) scale(.7) legend(off)
*

pe_revenue