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]

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: AW: RE: scalar and calculations |

Date |
Fri, 16 Apr 2010 16:33:47 +0200 |

<> Tomas may also want to stay alert to the problem discussed in http://www.stata-journal.com/sjpdf.html?articlenum=dm0021 HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nick Cox Gesendet: Freitag, 16. April 2010 16:17 An: statalist@hsphsun2.harvard.edu Betreff: 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 n.j.cox@durham.ac.uk 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/

**References**:**st: scalar and calculations***From:*"Tomas Lind" <tomas.lind@ki.se>

**st: RE: scalar and calculations***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: AW: rename files - "! rename" doesn't work** - Next by Date:
**st: RE: rename files - "! rename" doesn't work** - Previous by thread:
**st: RE: scalar and calculations** - Next by thread:
**st: SV: RE: scalar and calculations** - Index(es):