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

st: RE: set obs equal to a scalar

From   "Nick Cox" <>
To   <>
Subject   st: RE: set obs equal to a scalar
Date   Tue, 16 Sep 2008 19:16:17 +0100

The syntax you want is 

. set obs `=ObsPerPerson' 

Or in extremis 

. set obs `=scalar(ObsPerPerson)' 

-- because (the name of) a scalar is not a number, or (the name of) a
local macro, as implied by other syntaxes you tried. 

Irritating, but true. 

A separate implication is that I would not put this number in a scalar,
because of the extra effort needed to get it out again. To automate -set
obs-, I would use a local macro. 

-display-'s job is to go the extra mile [sc. kilometre], as I mused not
so long ago on this list, so what -display- can do is not a precedent
for other commands. 


Jacob Wegelin

In the example below, it is impossible to set obs equal to a scalar
value 5, but it is possible to set obs to equal the same value 5 when it
is stored in a local macro.  Why? Is there no way to set obs equal to a

. clear

. scalar define ObsPerPerson=5

. di ObsPerPerson

. set obs ObsPerPerson
'ObsPerPerson' found where integer expected

. set obs `ObsPerPerson'
invalid syntax

. set obs "`ObsPerPerson'"
'"' found where integer expected

. local heyThere 5

. set obs `heyThere'
obs was 0, now 5

*   For searches and help try:

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