Bookmark and Share

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


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

st: RE: counting number of variables in a varlist


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: counting number of variables in a varlist
Date   Wed, 15 Jun 2011 23:08:24 +0100

After 

. describe <varlist> 

r(k) contains the number of variables in <varlist>. 

After 

unab vars : <varlist> 
di `: word count `vars''

you get to see how many variables there are.

If you go 

. di c(k)

you get to see how many variables there are in memory. 

With -x1 x2- I can count them by hand and get 2 consistently, but this may not be a skill taught nowadays. 

Nick 
[email protected] 

ali hashemi

I would like to count the number of variables in a varlist. The way I manage
to do this is as follows:

local i=0
foreach var in x1 x2 {
local i=`i'+1
}

I was wondering if there is any built-in command which does the same thing.

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


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