Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | tashi lama <ltashi32@hotmail.com> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: could someone pls explain me this |
Date | Mon, 30 Apr 2012 18:29:35 +0000 |
is summarize in the code to specify the variable we are looking to find r(min) ? Looks like it... Thanx.. ---------------------------------------- > From: ltashi32@hotmail.com > To: statalist@hsphsun2.harvard.edu > Subject: RE: st: could someone pls explain me this > Date: Mon, 30 Apr 2012 18:24:34 +0000 > > thank you. I still have some clouds. > > 1.Why do we have to summarize the temp var? > > 2.Minimum such obs no r(min). Are we looking the minimum obs in the tempvar? Is it 3 in the following example? > > > > epcom noncom __000001 | > |------------------------------------------| > 1. | 18001 Acheres . | > 2. | 18002 Ainay-Le_Vieil . | > 3. | 18003 Les Aix -d'Angillion 3 | > 4. | 18004 Allogny . | > 5. | 18005 Allouis . | > > > > > 3. Could we have said instead of minimum or maximum no, non-missing obs no because there is only one obs in tempvar? > > ---------------------------------------- > > Date: Mon, 30 Apr 2012 18:37:56 +0100 > > Subject: Re: st: could someone pls explain me this > > From: njcoxstata@gmail.com > > To: statalist@hsphsun2.harvard.edu > > > > The code > > > > tempvar tv1 > > gene `tv1'=_n if depcom==18003 > > summ `tv1', meanonly > > local index=r(min) > > local mymacro=nomcom[`index'] > > drop `tv1' > > > > is a way of looking up the value of -nomcom- when -depcom- is 18003. > > The temporary variable contains observation numbers for which -depcom- > > is 18003. A certain way of finding such an observation if any exist is > > to find the minimum such observation number. The maximum would do fine > > as an alternative. The code could be shortened > > > > tempvar tv1 > > gene `tv1'=_n if depcom==18003 > > summ `tv1', meanonly > > local mymacro=nomcom[r(min)] > > drop `tv1' > > > > The main point of similar code is to automate value look-up. It's > > usually a long-winded way to proceed if you are working interactively. > > > > Nick > > > > On Mon, Apr 30, 2012 at 6:24 PM, tashi lama <ltashi32@hotmail.com> wrote: > > > > > I am doing sth similar to what I found in archive titiled "Re: st: save the value of a string variable into a macro". I am not sure if I followed the code although it looks relatively st. forward. > > > > > > > > > > > > Here is the dataset and goal > > > > > > +-----------------------------+ > > > | depcom nomcom | > > > |-----------------------------| > > > 1. | 18001 Acheres | > > > 2. | 18002 Ainay-le-Vieil | > > > 3. | 18003 Les Aix-d'Angillon | > > > 4. | 18004 Allogny | > > > 5. | 18005 Allouis | > > > +-----------------------------+ > > > > > > Where depcom is an id. I want to save a specific values of the variable "nomcom" into a variable, for example, I want to obtain : > > > . di "`mymacro'" > > > Archeres > > > > > > > > > > > > The code is > > > > > > > > > > > > tempvar tv1 > > > gene `tv1'=_n if depcom==18003 > > > summ `tv1', meanonly > > > local index=r(min) > > > local mymacro=nomcom[`index'] > > > drop `tv1' > > > > > > > > > > > > > > > I follow line 1 and 2. I am not sure why we need line 3. Line 4 established a macro which is used in line 5. But, I don't follow why the macro takes r(min) as expression. I would think the macro `index' should capture the value(the only value in fact) in tv1. > > > > * > > * 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/ > * > * 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/ * * 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/