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]

st: AW: RE: SV: RE: scalar and calculations


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: RE: SV: RE: scalar and calculations
Date   Fri, 16 Apr 2010 17:30:14 +0200

<> 

" Another issue is that there is a Stata command -test-, which may well be
getting in the way here."


It is definitely bad practice to use names of official Stata commands for
one`s -program-s, but if there was confusion in this particular case,
official -test- would certainly complain about a sore lack of previous
estimation results, via error r(301).



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Nick Cox
Gesendet: Freitag, 16. April 2010 17:13
An: [email protected]
Betreff: st: RE: SV: RE: scalar and calculations

Your program can't see your tempname. Your tempname must be specified in the
same program (namespace) and before it is used, as I was trying to indicate,
or imply. 

Another issue is that there is a Stata command -test-, which may well be
getting in the way here. 

Nick 
[email protected] 

Tomas Lind

Thanks Nick,

This code works (with tempname v2), but it does not work if I specify `v2'
in the -return- and -simulate- statements. That makes me a bit confused when
you say " Alternatively, and better, 
tempname v 
scalar `v' =



capture program   drop test
program  test , rclass
	version 10   
      syntax [, n(integer 1) ]
	drop _all
	set obs `n'
      gen zz=10 
	sum zz
	scalar x = r(mean) 
	tempname v2
	return scalar v2 = x^2 * `n'		
end

tempname z
simulate z = r(v2) , reps(10) : test , n(100)
sum z			// OK fungerar


/Tomas



-----Ursprungligt meddelande-----
Från: [email protected]
[mailto:[email protected]] För Nick Cox
Skickat: den 16 april 2010 16:17
Till: [email protected]
Ämne: st: RE: scalar and calculations

You are confusing scalars with their names, which may or may not be
temporary. 

Scalars need not have temporary names. In your case the scalar has a
permanent name, v, which you assigned to it. 

You could use v rather than `v' throughout -- so long as no variable is
named, or unambiguously abbreviates to, v.

Alternatively, and better, 

tempname v 
scalar `v' = 

Conversely, the `v' notation suggests to Stata that it should find something
with the temporary name specified, and in your case there is no such beast. 

Nick 
[email protected] 

Tomas Lind

Scalar can´t do calculations?


I am trying to do some simulations. In a simplified version of my code, this
works (part of code shown) where n is sample size:

scalar v = r(mean) 
return scalar v2 = (`v'+2) * `n'		// No error messages

But this does not work:
scalar v = r(mean) 
return scalar v2 = (`v'^2) * `n'		// Error, ^2 invalid name


This is part of the full code and I get an error for ^2.
summarize ln_large
scalar v = (r(sd)^2)/2
return scalar mlk = exp(r(mean)) * (1 + ((`n'-1)/`n') +
 ( ((`n'-1)^3)/(`n'^2*(`n'+1)*2*1 ) ) * (`v'^2/(    2*1) )  +
 ( ((`n'-1)^5)/(`n'^3*(`n'+1)*(`n'+3)*3*2*1 ) ) * (`v'^3/(  3*2*1) )  + 
 ( ((`n'-1)^7)/(`n'^4*(`n'+1)*(`n'+3)*(`n'+5)*4*3*2*1 ) ) * (`v'^4/(4*3*2*1)
) )

How shall I do to calculate the value for mlk?


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


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