Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: More efficient way to calculate formula


From   Nikolaos Kanellopoulos <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: More efficient way to calculate formula
Date   Mon, 13 Jan 2014 10:59:50 +0000 (GMT)

Dear all,

I have the sales of some firms for various products by consumer and I want to estimate the following: Total sales of firm i of product j / (Number of consumers that contribute 60% of sales + 1).

My thought is the following:clear
webuse productivity

//year will be firm i
//region will be the product j
//state will be the consumer; can appear multiple times, ie buy from many firms
//gsp will be the sales

sort year region state gsp

bys year region (gsp): cumul gsp, gen(v1)
bys year region (gsp): cumul gsp, gen(v2) f

gen v5=floor(10*v1)
recode v5 (7/10=6) //This is done in case 60% is not observed
gen temp=.
egen tot_p=total(gsp) , by(year region)
bys year region v5 (gsp) : gen i=_n

bys year region :replace temp = tot_p/(v2+1) if v5==6 & i==1 

Is there a better-more efficient way to do this because I have quite a lot of consumers and the above code takes too long.

Thanks in advance
Nikos

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index