Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: A simple program with a weird behavior


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: A simple program with a weird behavior
Date   Mon, 07 Jul 2008 09:40:27 +0200

Am Montag, den 07.07.2008, 01:59 -0300 schrieb
[email protected]:
> It is not rare for me to write Stata programs and face problems like the
> one just mentioned below. I will be very grateful for any expert opinion.

...

> */------------------------------start--------------------------------
> 
> capture program drop example
> *! example v1. TVP 2008
> program define example, rclass byable(recall) sortpreserve
> version 9.0
> syntax [varlist], LOCI(integer) MEANS(real) SDS(real) ORS(string) K(real)
> MODEL(string) pa(string) INCREMENT(real)
> 
> 
> 	scalar n_x = 100000
> 	scalar PREV = "`k'"
> 	scalar affected =  PREV*n_x
> 
> 
> 
> end
> 
> */------------------------------end--------------------------------
> 
> 
> . example, means(100) sds(1) ors(1.2,1.3,1.5) loci(4) k(0.3)
> model(genetic_stuff) pa(0.4) increment(0.000001)
> type mismatch
> r(109);
> 
> If I delete the last line:
> 
> scalar affected =  PREV*n_x
> 
> the program works fine.

Because of the quotation marks, you have stored the real number `k' as a
string in the scalar PREV. You can do that, but then you cannot multiply
this string with a real number, as you try to do in the next line.  The
following code should work

scalar PREV = `k'
scalar affected = PREV*N_x

or even

scalar affected = `k'*N_x

Hope this help
Uli

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index