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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Product within a variable |

Date |
Thu, 12 Jun 2003 17:37:20 +0100 |

Mario Gamboa-Cavazos > I am struggling to compute a constant of products within a variable. > What I am trying to do is something very similar to what the 'egen' > command with the option 'sum' and 'by(.)' does, except that > I would need > something like a multiplication option. > > My dataset is a panel of monthly stock returns and I want > to compute the > follwing: > > - For each company and for each year: The product of > (1+r_t) where r is > the monthly stock return in month t. More specifically, my dataset > looks like: > > Company Year Month Return What I need: > Pi^12_1(1+r_t) > 1 1990 1 .33 > constant > for 1990 firm 1 > 1 1990 2 .44 > constant > for 1990 firm 1 > . . . . > constant > for 1990 firm 1 > . . . . > constant > for 1990 firm 1 > . . . . > constant > for 1990 firm 1 > 1 1990 12 .55 > constant > for 1990 firm 1 > 1 1991 1 .23 > constant > for 1991 firm 1 > 1 1991 2 .43 > constant > for 1991 firm 1 > . . . . > constant > for 1991 firm 1 > . . . . > constant > for 1991 firm 1 > . . . . > constant > for 1991 firm 1 > 1 1991 12 .43 > constant > for 1991 firm 1 > 2 1990 1 .87 > constant > for 1990 firm 2 > 2 1990 2 .98 > constant > for 1990 firm 2 > . . . . > constant > for 1990 firm 2 > . . . . > constant > for 1990 firm 2 > . . . . > constant > for 1990 firm 2 > 2 1990 12 .65 > constant > for 1990 firm 2 > . . . . . > . . . . . > . . . . . > > and so on for nearly 2,000 companies and ten years. > > If any of you has any good suggestions I would greatly > appreciate it, > especially if it can deal with missing return data. I don't know what white magic you want for missing values. I think you will need to spell that out. I would try something like this: bysort firm year (month) : gen product = return[1] by firm year : replace product = return * product[_n-1] But for a fuller implementation with more bells and whistles, Phil Ryan has -egen- functions which should help. Type . findit egen product Nick n.j.cox@durham.ac.uk * * 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/

**References**:**st: Product within a variable***From:*"Mario Gamboa-Cavazos" <mgamboa@nber.org>

- Prev by Date:
**st: RE: ado dir behavior bug?** - Next by Date:
**RE: st: Sample Size foir Conditional Logistic Regression** - Previous by thread:
**st: Product within a variable** - Next by thread:
**st: Graph matrix with non-linear regression lines** - Index(es):

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