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: RE: How to pass scalar argument to a function's options (-prvalue- in this case)


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: RE: How to pass scalar argument to a function's options (-prvalue- in this case)
Date   Mon, 19 Dec 2011 18:07:10 +0000

Richard Williams has often emphasised that there are multiple versions of Scott Long's add-ons around, which is what we are talking about here. However, that is a contingent detail, although I do believe him and -findit prvalue- supports the contention in this case. 

The point about specifying where you download from is a point of principle. Let's reasonably assume that a range of readers are interested in your post, from people who can't answer the question but are interested in doing something similar, to people who might answer the question. Even if there were only one download location no-one is harmed and many people are helped by saying what that location is. Often there is more than one location and sometimes which location was used is crucial to understanding the question, as when people have downloaded an out-of-date or buggy version. 

You can't see it happening, but I often delete posts without commenting if people don't explain themselves well. (You can see it if I complain about that.) And I know that many active people have similar attitudes. So, it's also in posters' best interests to explain themselves fully, as their chance of getting a good answer goes up. 

I quite like a lot of the small detective work in identifying and fixing little problems, but having to work out _precisely_ which programs people are using is no fun at all.

I think people sometimes forget that this is a discussion list, not a help line. No one is obliged to answer anything! Even the more active posters usually have a curmudgeonly side and routinely consign many posts to oblivion if they are too badly explained to understand. 

Nick 
[email protected] 


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Richard Herron
Sent: 19 December 2011 17:45
To: [email protected]
Subject: Re: st: RE: How to pass scalar argument to a function's options (-prvalue- in this case)

Thanks, Nick, for several lessons. Both of your suggestions work
(i.e., forcing evaluation with `= ' and skipping the -scalar- step)
and I will paste both versions below.

Re installing -prvalue-, I am still confused. The only way I can
install is -findit prvalue- (i.e., -ssc install st0094-, -ssc install
spost-, -ssc install prvalue-, -net install st0094-, and other
variants fail). Maybe I should give up on resolving blind spots?

* begin working code with two solutions
sysuse auto, clear
generate log_weight = log(weight)
generate price_dummy = (price > 10000)
probit price_dummy log_weight mpg length

* evaluate the scalar with `= '
summarize weight, meanonly
scalar log_mean_weight = log(r(mean))
prvalue, x(log_weight = `=log_mean_weight')

* with `= ' I can skip the scalar altogether
summarize weight, meanonly
prvalue, x(log_weight = `=log(r(mean))')
* end code

On Mon, Dec 19, 2011 at 12:23, Nick Cox <[email protected]> wrote:
> In addition, -prvalue- is a command (not a function).
>
> Nick
> [email protected]
>
> -prvalue- is a user-written command from wherever you downloaded it from. Please remember that you are asked to explain this. Giving authors is not what is asked for: the ideal is that people can immediately download from the same place for themselves.
>
> I don't know the insides or even outsides of -prvalue-, but I'd guess what you want is this.
>
> I don't think the issue is whether you understand scalars, but rather that you are expecting -prvalue- to understand that a particular name is a scalar name. I don't think that a typical program will do that amount of work for you in deciphering option arguments. In any case, if -prvalue- wants a value, passing it a name is at best indirect. The error message clearly implies that -prvalue- wants to feed on a number, not a name.
>
> Instead of
>
> summarize weight, meanonly
> scalar log_mean_weight = log(r(mean))
> prvalue, x(log_weight = log_mean_weight)
>
> try
>
> summarize weight, meanonly
> prvalue, x(log_weight = `=log(r(mean))')
>
> The framing `=  ' obliges Stata to evaluate its argument and pass it to -prvalue- as a numeric result.
>
> It's possible that wrapping the argument in -scalar()- would help, but as above using a scalar as intermediary seems unnecessary here.
>
> I've given up hoping that I have no Stata blindspots left.
>
> Nick
> [email protected]
>
> Richard Herron
>
> I think this is a gross conceptual error I have in how Stata uses
> scalars, but I have an example using Long and Xu's -prvalue-.
>
> I would like to evaluate a -probit- model with a logged right hand
> side variable at the "log of the mean" instead of at the "mean of the
> log." I find the mean with -summarize- then store the log with
> -scalar-, but when I pass -log_mean_weight- as an argument to the
> -x()- option in -prvalue- I get the following error
>
> 'log_mean_weight' found where number expected
>
> Here is some reproducible code
>
> * begin code
> sysuse auto, clear
> generate log_weight = log(weight)
> generate price_dummy = (price > 10000)
> probit price_dummy log_weight mpg length
>
> * I would like to determine probability at the log of mean weight
> summarize weight, meanonly
> scalar log_mean_weight = log(r(mean))
> prvalue, x(log_weight = log_mean_weight)
> * end code
>
> I have also unsuccessfully tried to use a -tempname- instead of
> -scalar-, but in that case -prvalue- returns
>
> '__000000' found where number expected
>
> Thanks! I think (well, hope) that this scalar problem is my last major
> Stata blind spot.
>
> *
> *   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