# st: RE: Panel data. Multiple variables generation.

 From "Martin Weiss" To Subject st: RE: Panel data. Multiple variables generation. Date Fri, 18 Dec 2009 20:00:48 +0100

```<>

You want to look at the -sum()- function, but deeper answers require an
excerpt of your data. You can condition within the argument to the function,
as seen here:

*******

clear*
set obs 10

gen num=_n

gen var=rnormal()<.5

gen runningsum=sum(var)
gen runningsumodd=sum(var*mod(_n,2))

list, noo ab(20)
*******

If you want a constant sum, look at -egen, total()-...

HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Laia Cirera i
Crivillé
Sent: Freitag, 18. Dezember 2009 19:50
To: statalist@hsphsun2.harvard.edu
Subject: st: Panel data. Multiple variables generation.

Good afternoon,

I am working with a panel data set, which contains data on bilateral trade
flows for 103 countries and for 9 periods of time (t), where (i) are
exporting countries and (j) are importing countries .

For each pair of trading countries (ij), and for each period of time (t), I
have the variable Yijt. I need to create a new variable (Xit), which, for
each case where country (i) is exporting and for each period of time (t),
will add Yijt terms up. For example, if country i=1 and t=1 (X11), to obtain
X11, I take each case of period t=1 where country 1 is exporting (i=1), and
add all Yijt terms up. If country i=2 and and t=1 (X12), I take each case of
period t=1 where country 2 is exporting (i=2), and add all Yijt terms up. So
Xit will vary by exporting country(i) and period of time(t), but will be the
same across bilateral pair of countries (ij) which have the same exporter
country (i) and period of time (t).

Do you know which command I should use?

Thanks a lot.

Laia
_________________________________________________________________
¡Ya está aquí Windows Live Spaces! Ahora podrás crear fácilmente tu propio
sitio Web.
http://spaces.live.com/signup.aspx
*
*   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/
```