Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Austin Nichols <austinnichols@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Doing something an observation-specific number of times |

Date |
Tue, 28 Aug 2012 13:23:11 -0400 |

robert hartman <rohartman@gmail.com>: If you google "sum of finite geometric series" or somesuch, you should find an easy answer. On Tue, Aug 28, 2012 at 12:45 PM, robert hartman <rohartman@gmail.com> wrote: > Hi Listers, > Imagine that observation 1 has v1 and v2 values of .41 and 78, > respectively. There are many other observations like this, where v1 > values lie on the unit interval and v2 values are positive integers > (let's say the upper bounded is 600). I want to create a new variable > and store in it the results of an algebraic equation that uses the v1 > and v2 values from same row, as well as some constants, and where > "observation-specific exponentiation" is happening. For example, let's > say I want to add a constant to v1 raised to some power and then > divide that by some other constant. And let's say that the "some > power" is every power from 1 to the v2 value inclusive (e.g., 1 > through 78 in this case, 1 through 2 if the v2 value is 2...) and then > sum up those terms. For example, for observation 1, the new obs 1 v3 > value=((1+(.41^1))/2) + ((1+(.41^2))/2) ...((1+(.41^77))/2) + > ((1+(.41^78))/2). The specific use case is convoluted, and I don't > think in-depth understanding of it is critical to the programming > (we'll see). > > I have begun to think of some klugy ways of doing this via looping or > even the expand command. However, whereas my Stata programming skills > are mediocre and have been acquired ad hoc, I thought some of you > might have some insights as to a relatively computationally efficient > and/or lines-of-code efficient way of doing this kind of thing. There > may even be some kind of obvious (to you, not me) algebraic workaround > that I'm not catching. > > Thanks, > Rob * * 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/

**References**:**st: Doing something an observation-specific number of times***From:*robert hartman <rohartman@gmail.com>

- Prev by Date:
**Re: st: Getting confidence intervals from lincom** - Next by Date:
**RE: st: Getting confidence intervals from lincom** - Previous by thread:
**st: Doing something an observation-specific number of times** - Next by thread:
**Re: st: Doing something an observation-specific number of times** - Index(es):