Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
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 | Tue, 29 Oct 2013 23:24:39 +0000 |
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/