Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: How to use an independent grid to perform calculations for each observations

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: st: How to use an independent grid to perform calculations for each observations Date Wed, 10 Oct 2012 21:52:26 +0100

```The Stata way is not necessarily the MATLAB way, fine program though
that is. (Not STATA and Matlab!)

I don't understand all of this but nevertheless will make a guess. You
have say 50 variables and you want say 50 more variables. Creating
such a large extra batch only raises the question of how you are going
to work with all those extras. Do you have a plan for that?

And with other such batches of extras you might create for each
related problem.

The clue is that they are all variables of the same kind. Normally
that implies a loop over variables, but if you restructure you may be
able to avoid such a loop.

It's more likely that you need to -reshape long- and then work with
far fewer variables.

If you don't get a better answer than this, I would post a very simple
analogue of your problem showing numbers.

Nick

On Wed, Oct 10, 2012 at 8:21 PM, Daniel Almar de Sneijder
<dasneijder@gmail.com> wrote:

> Does anybody perhaps know a way to perform calculations for each
> observant using a grid. More specific,
>
> I have variables that record the earnings of respondents, say
> RwIEARN50 ... RwIEARN99.
> I want to index these variables by using a grid. The trick is however
> that each observation refers to respondents. Each respondent has a
> different year of birth and year of eligibility and therefore a
> different indexing factor needs to be used.
>
> So basically I have a N-by-M matrix, call it S, with on the rows the
> indexing factor of the earnings at each year i = 1,...,N and on the
> columns the year eligibility j = 1,...,M
>
> Now I want to construct variables RwINDEX50 ... RwINDEX99 that record
> the indexing factor for all respondents 1....R (rows), which basically
> depend on the year of eligibility of each respondent and the name of
> the variable (50...99).
>
> In formula, this would correspond to:
>
> year of eligibility = date of birth of `r' + 62
> replace RwINDEX`year'[`r'] = S[`year']['year of eligibility']
>
>
> Basically this is something very simpel that can be done within 5
> minutes with Matlab. In STATA however this looks like impossible?
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```