Statalist


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

Re: st: A simple program with a weird behavior


From   "Eva Poen" <[email protected]>
To   [email protected]
Subject   Re: st: A simple program with a weird behavior
Date   Mon, 7 Jul 2008 11:19:51 +0100

Tiago,

> 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

Others have already explained to you where the problem is. On a
different note, beware of possible name clashes between scalars and
variables, even scalars and abbreviated variables names, as the
example below demonstrates. To avoid the possibility of a name clash,
you can use -tempname- for your scalars inside your programs, or use
the -scalar()- function when referring to scalars.

HTH,
Eva

*** example of how not to do it
capture program drop test
program test
    syntax , K(integer) L(integer)
    scalar first = `k'
    scalar second = `l'
    scalar product = first*second
    di product
end

clear
set obs 1
gen first = 111
gen second = 222
test , k(2) l(3)

rename second seconds
test , k(2) l(3)

gen product = 555
test , k(2) l(3)
*
*   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