Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: Using Sample Command with Scalar Not Number

From   Steve Samuels <>
Subject   Re: st: Using Sample Command with Scalar Not Number
Date   Sun, 20 Jan 2013 14:09:35 -0500

You can also use a local macro

local a  5
sample `a', count


On Jan 20, 2013, at 9:46 AM, Nick Cox wrote:

sample `=scalar(A)', count

will ensure that -sample- sees the value of scalar A because the evaluation

= scalar(A)

takes place before -sample- gets to work. See -help macro- under

The -scalar()- ensure no clash with variable names starting with "A".


On Sun, Jan 20, 2013 at 2:27 PM, Maisie Harris <> wrote:
> I am running a loop of code in which I'd like to use the sample
> command, but instead of stating the specific number I want to sample
> I'd like to refer to a previously defined scalar.
> A simplified version of what I'm trying to do is:
> scalar A=5
> sample A, count
> However, when I run the code it says that it finds A when it is
> expecting a number. Is there a simple way to do this? Do I need to
> redefine the scalar somehow?
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index