... , by(octy)
Nick
[email protected]
Nick Cox
> Your code is twice as long as needed. As -egen, total()-
> can feed on expressions, consider
>
> egen x1 = total((1/dist) * exp)
>
> -egen, total()- is the current name of -egen, sum()-.
>
> Nick
> [email protected]
>
> Roy,Suryadipta
>
> > I probably just sorted it out without any programming-
> > would get beck for more help later on!
> >
> > g dt=(1/dist)*exp
> > egen x1=sum(dt), by(octy)
>
> Roy,Suryadipta
>
> > > I have data on 5 countries (a, b, c, d, e) for octy,
> > >dcty, dist, d1, and exp. The data are given below:
> > >
> > > octy dcty dist d1 exp x1 x2
> > > a c 5 1 50 35 50
> > > a d 4 0 100 35 50
> > > b c 3 0 50 29.167 0
> > > b d 8 0 100 29.167 0
> > > c d 2 1 50 25 50
> > > d c 2 1 100 50 100
> > > e c 1 0 50 150 0
> > > e d 1 0 100 150 0
> > >
> > > I need to generate x1 and x2 for all countries based on
> > >the following formula:
> > >
> > > x1 (country a)=
> > >1/dist(a,c)*exp(c)+1/dist(a,d)*exp(d)=1/5*50+1/4*100=35.
> > >
> > > x2 (country a)=
> > >d1(a,c)*exp(c)+d1(a,d)*exp(d)=1*50+0*100=50, and so on
> > >for all countries.
> > >
> > > With over 200 countries, this obviously needs some
> > >programming and it would be great to get some help here.
*
* 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/