# 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.

Nick
n.j.cox@durham.ac.uk

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
scalar?

. clear

. scalar define ObsPerPerson=5

. di ObsPerPerson
5

. set obs ObsPerPerson
'ObsPerPerson' found where integer expected
r(198);

. set obs `ObsPerPerson'
invalid syntax
r(198);

. set obs "`ObsPerPerson'"
'"' found where integer expected
r(198);

. local heyThere 5

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

*
*   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/
```