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]

RE: st: Assigning value of a function to a local macro


From   Navid Asgari <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: Assigning value of a function to a local macro
Date   Thu, 10 May 2012 23:53:01 +0800

Thanks Phil! It is a good solution to use scalars.

But, on a side note, min() can work on one variable too

e.g.:

generate minv=min(variable1)

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Phil Clayton
Sent: Thursday, May 10, 2012 6:02 PM
To: [email protected]
Subject: Re: st: Assigning value of a function to a local macro

min() doesn't do what you think it does. It's more for this kind of thing:
gen newvar=min(var1, var2, var3)
or
gen newvar=min(var1, var1[_n-1])
or
summarize price
display min(r(mean), r(p50))

To get the lowest value of the variable year in the dataset, I would suggest:
summarize year, meanonly
local byear=r(min)

Phil

On 10/05/2012, at 7:40 PM, Navid Asgari wrote:

> Hi Statalist,
> 
> I am trying to assign the value of a function to a local macro, but I get "Invalid Syntax"?
> 
> 
> I type:
> 
> local byear=min(year)
> 
> year is the variable whose minimum has to be saved in the local macro "byear"
> 
> Any idea?
> 
> Thanks,
> Navid
> 
> 
> 
> 
> *
> *   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/


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