Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: passing indefinite no of arguments


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: passing indefinite no of arguments
Date   Mon, 2 Apr 2012 23:14:35 +0100

It does work; I edited incorrectly.

. di mdy(1,5,2010) +  1
18268

On Mon, Apr 2, 2012 at 11:04 PM, Nick Cox <njcoxstata@gmail.com> wrote:
> Evidently,  -date- is a Stata date variable, so although you see
> 05jan2010 it is a numeric variable and you can check the first value
> directly.
>
> . di mdy(1,5,2010) + 1
> 18269
>
> The program does what you asked for -- you specify some variables, you
> get a row total of the rest -- and also exactly what I warned you
> against, that if the rest are not homogeneous that will break it as
> far as you are concerned.
>
> Also, a do-file does not take options.
>
> Nick
>
> On Mon, Apr 2, 2012 at 9:37 PM, tashi lama <ltashi32@hotmail.com> wrote:
>>
>>
>> I am sorry. I had used r[] instead of r[]. Looks like it is working although I am not sure if it is giving me the right result.
>>
>>
>>
>> date var_34 var_50 var_90
>> 05jan2010 2 1 1
>> 06jan2010 3 2 4
>> 07jan2010 4 8 5
>> 08jan2010 5 4 3
>> 09jan2010 6 3 2
>>
>>
>>
>>
>>
>> so I invoked sumrest var_34 var_50, generate(g), I got
>>
>>
>>
>> date var_34 var_50 var_90 g |
>>  |----------------------------------------------|
>>  1. | 05jan2010 2 1 1 18268 |
>>  2. | 06jan2010 3 2 4 18272 |
>>  3. | 07jan2010 4 8 5 18274 |
>>  4. | 08jan2010 5 4 3 18273 |
>>  5. | 09jan2010 6 3 2 18273 |
>>  +----------------------------------------------+
>>
>>
>>
>> Any idea? Also, when I run this as a do file, I get option generate() not allowed....
>>
>>
>>
>> Thank you....
>>
>> ----------------------------------------
>>> Date: Mon, 2 Apr 2012 20:32:09 +0100
>>> Subject: Re: st: passing indefinite no of arguments
>>> From: njcoxstata@gmail.com
>>> To: statalist@hsphsun2.harvard.edu
>>>
>>> I tested it and found two bugs. Please try this
>>>
>>> program sumrest
>>> version 8.2
>>> syntax varlist(numeric) [if] [in] , Generate(string)
>>> marksample touse, novarlist
>>> qui count if `touse'
>>> if r(N) == 0 error 2000
>>> confirm new var `generate'
>>> unab all : _all
>>> local varlist : list all - varlist
>>> local varlist : list varlist - touse
>>> egen `generate' = rowtotal(`varlist') if `touse'
>>> end
>>>
>>>
>> &#!
>>  10;>
>>> On Mon, Apr 2, 2012 at 8:20 PM, tashi lama <ltashi32@hotmail.com> wrote:
>>> > Hello Nick,
>>> >
>>> >
>>> >
>>> > I tried running the code with syntax as a do file. There was an error which reads option generate() not allowed. Any idea?
>>> >
>>> >
>>> >

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


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index