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

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

From |
Nick Cox <njcoxstata@gmail.com> |

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

Subject |
Re: st: RE: generate new variables using the first record of the group |

Date |
Wed, 30 Oct 2013 00:29:14 +0000 |

The same answer and the same question. To get your -city_1- and -city_2- it is sufficient (although not necessary) to use any value of -city- that is equal to 30 or 12 respectively. But why do you want to do this? Nick njcoxstata@gmail.com On 29 October 2013 23:53, Song, Lin <Lin.Song@kingcounty.gov> wrote: > Thanks Sergiy and Nick. Sergiy told me a command that I did not know. > > On the other hand, I did not ask my question clearly. I was actually thinking something like the question below: > > For the following dataset , I'd like to generate two new variables in the last two columns (city1_n and city2_n) as shown below based on the first three columns. I thought I could use egen. > > id city city_n city1_n city2_n > 1 1 30 30 12 > 2 1 30 30 12 > 3 1 30 30 12 > 4 2 12 30 12 > 5 2 12 30 12 > 6 2 12 30 12 > 7 2 12 30 12 > 8 . 30 12 > 9 . 30 12 > 10 . 30 12 > > Thanks. > > Lin > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox > Sent: Tuesday, October 29, 2013 4:25 PM > To: statalist@hsphsun2.harvard.edu > Subject: Re: st: RE: generate new variables using the first record of the group > > Sergiy's answer is perfect, naturally, but quite why you would want to do this remains open. For some graphical purposes, a constant variable can be useful, but otherwise a constant is often better stored in a scalar or local. > > Nick > njcoxstata@gmail.com > > > On 29 October 2013 22:49, Sergiy Radyakin <serjradyakin@gmail.com> wrote: >> Lin, use the square brackets to address the particular observation of >> a variable: >> >> sysuse auto >> generate newvar=price[7] >> >> Creates a variable newvar, which is equal to the 7th observation of >> existing variable price. >> >> Best, Sergiy Radyakin >> >> >> On Tue, Oct 29, 2013 at 6:02 PM, Song, Lin <Lin.Song@kingcounty.gov> wrote: >>> Dear Stata users? >>> >>> How do I generate a new variable with its value for all observations equals to the first observation or the nth observation of another variable? >>> >>> Thanks. >>> >>> Lin >>> >>> >>> >>> >>> * >>> * 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/ >> * >> * 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/ > * > * 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/ > > > > * > * 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/ * * 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/

**Follow-Ups**:**Re: st: RE: generate new variables using the first record of the group***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**st: RE: generate new variables using the first record of the group***From:*"Song, Lin" <Lin.Song@kingcounty.gov>

**Re: st: RE: generate new variables using the first record of the group***From:*Sergiy Radyakin <serjradyakin@gmail.com>

**Re: st: RE: generate new variables using the first record of the group***From:*Nick Cox <njcoxstata@gmail.com>

**RE: st: RE: generate new variables using the first record of the group***From:*"Song, Lin" <Lin.Song@kingcounty.gov>

- Prev by Date:
**Re: st: tempvar versus tempname** - Next by Date:
**st: SROOT program - test seasonal unit root** - Previous by thread:
**RE: st: RE: generate new variables using the first record of the group** - Next by thread:
**Re: st: RE: generate new variables using the first record of the group** - Index(es):