Bookmark and Share

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]

R: Re: st: single elements of varlist


From   "[email protected]" <[email protected]>
To   <[email protected]>
Subject   R: Re: st: single elements of varlist
Date   Mon, 28 Mar 2011 10:13:51 +0200 (CEST)

thanks, it works!

>----Messaggio originale----
>Da: [email protected]
>Data: 28-mar-2011 10.08
>A: <[email protected]>
>Ogg: Re: st: single elements of varlist
>
>In a word, -tokenize-.
>
>program myprog, rclass
>          syntax varlist(numeric min=3) [if] [in]
>          marksample touse
>          qui count if `touse'
>          if r(N) == 0 error 2000
>
>           tokenize "`varlist'"
>           su `1' if `touse', meanonly
>           local mean1 = r(mean)
>
>           su `2' if `touse', detail
>           local median2 = r(p50)
>
>           su `3' if `touse'
>           local sd3 = r(sd)
>
>           return scalar results = `mean1' + `median2' + `sd3'
>end
>
>Nick
>
>> On Mon, Mar 28, 2011 at 8:53 AM, [email protected]
>> <[email protected]> wrote:
>
>>> I am new to programming and I have a basic problem. I need to refer to 
the
>>> single variables in "varlist" and I am not sure how. For example, I might 
to
>>> get the sum of: the mean of the first variable, the median of the second
>>> variable and the standard deviation of the third variable.
>
>>> program define myprog, rclass
>>> syntax varlist
>>> get the mean of variable 1
>>> get the median of variable 2
>>> get the standard deviation of variable 3
>>> return scalar results=(sum of the previous three values)
>
>*
>*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index