Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Tomas Lind" <tomas.lind@ki.se> |

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

Subject |
st: scalar and calculations |

Date |
Fri, 16 Apr 2010 16:11:49 +0200 |

Dear listers, 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? /Tomas * * 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/

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

- Prev by Date:
**Re: st: Store datafile at minimum possible file size** - Next by Date:
**st: Stata implementation of difference-in-differences with binary outcomes** - Previous by thread:
**st: Multilevel modelling Stata tutorials** - Next by thread:
**st: RE: scalar and calculations** - Index(es):