Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Data management


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Data management
Date   Wed, 28 Feb 2007 23:03:43 -0000

Second try: 

levelsof octy, local(D) 
gen tshare = . 

qui foreach d of local D { 
	su tradeshare if octy == "`D'", meanonly
	replace tshare = r(mean) if dcty == "`D'" 
}

bysort octy : egen x1 = total(tshare * dist) 
	

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Nick Cox
> Sent: 28 February 2007 22:46
> To: [email protected]
> Subject: st: RE: Data management
> 
> 
> Looks like 
> 
> bysort octy : egen x1 = total(tradeshare * dist) 
> 
> Nick 
> [email protected] 
> 
> Roy,Suryadipta
>  
> > I had posted a similar query sometime back and did not get 
> > any response- so probably my question was not very clear. 
> > Here I have modified the query and it would be extremely 
> > helpful to get some help. The dataset is as follows:
> > 
> > octy	dcty	dist	tradeshare	x1
> > a	b	10	0.13	12.95
> > a	c	15	0.13	12.95
> > a	d	25	0.13	12.95
> > b	a	10	0.44	13.15
> > b	c	30	0.44	13.15
> > b	d	25	0.44	13.15
> > c	a	15	0.22	16.2
> > c	b	30	0.22	16.2
> > c	d	5	0.22	16.2
> > d	a	25	0.21	15.35
> > d	b	25	0.21	15.35
> > d	c	5	0.21	15.35
> > 
> > Value of x1 for octy a (=12.95) has been generated by the 
> > formula:
> > tradeshare(b)*dist(a,b)+tradeshare(c)*dist(a,c)+tradeshare(d)*
> > dist(a,d).
> > 
> > Similarly, x1 for octy b 
> > (=13.15)=tradeshare(a)*dist(b,a)+tradeshare(c)*dist(b,c)+trade
> > share(d)*dist(b,d), 
> > and so on for octy c and d.
> > 
> > I can do the above for 4 countries in Excel but with more 
> > than 150 countries, it gets extremely difficult. Any 
> > cooperation is highly appreciated.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index