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

From |
Ernest Berkhout <[email protected]> |

To |
[email protected], <[email protected]> |

Subject |
Re: st: assignment by indexing |

Date |
Tue, 03 Feb 2004 13:47:02 +0100 |

At 13:37 03/02/2004, Ben Pelzer wrote:

Not that basic, I think. At least I cannot think of a simple command to establish this. Many deppends on how exactly your index-variable looks. Does it takes the integer values 1 to 5? If that is the case, you might set up a loop using foreach or forvalues.Dear stata-users, Since I'm a stata-rooky this question probably is very basic. I'm looking for a way to copy the contents of a specific variable out of the list "x1 x2 x3 x4 x5" to a new variable, newvar, say. However, which variable to copy depends on the value of another variable, index, say. So I would need something like: generate newvar = x(index). How can I realize this in Stata? I looked through the P programming and the U user manual, but got stuck. Ben Pelzer.

But maybe a simpler option is to split the problem in seperate commands, like:

generate newvar = .

replace newvar = x1 if index==somevalue

replace newvar = x2 if index==someothervalue

etc. etc.

This can be extended if index is allowed to be within a certain range of values:

generate newvar = .

replace newvar = x1 if inrange(index,lowestvalue,highestvalue)

etc. etc.

Eventually you may use the function inlist of index is allowed to take on several integer values.

Grtz,

Ernest Berkhout

SEO Amsterdam Economics

University of Amsterdam

Room 3.08

Roetersstraat 29

1018 WB Amsterdam

The Netherlands

tel.:+ 31 20 525 1657

fax:+ 31 20 525 1686

http://www.seo.nl

===========================

A statistician: someone who insists

on being certain about uncertainty

===========================

*

* 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/

**Follow-Ups**:**RE: st: assignment by indexing***From:*"Ben Pelzer" <[email protected]>

**References**:**st: assignment by indexing***From:*"Ben Pelzer" <[email protected]>

- Prev by Date:
**st: RE: assignment by indexing** - Next by Date:
**Re: st: Re: winmail.dat** - Previous by thread:
**st: assignment by indexing** - Next by thread:
**RE: st: assignment by indexing** - Index(es):

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