I am not sure whether I understand exactly what you want to do, but
this may help.
1) You could loop over variable lists, along the following lines:
foreach first of varlist telephone* clock* cltv* bicycle* {
tabstat `first', s(mean n max min med) c(s)
}
2) If the order matters, you could write a more complicated loop,
maybe like this:
foreach first of varlist telephone clock cltv bicycle {
foreach second in no sh shno {
tabstat `first', s(mean n max min med) c(s)
capture tabstat `first'`second', s(mean n max min med) c(s)
}
}
(The capture is necessary because not all variables are included
with the same suffixes).
I don't know what you are trying to achieve with this, but there may
be more straightforward ways to do this. -collapse- and -reshape-
may be useful for you (again, depending on what you want to do).
HTH,
Philipp
Yusuke Taishi wrote:
I have a data set that contains variables like;
telephone
telephoneno
telephonesh
telephoneshno
clock
clockno
cltv
cltvno
bicycle
bicycleno
bicyclesh
bicycleshno
and many more. As you can see, they take the form of ;
"name of item"
"name of item"no; or
["name of item"sh / "name of item"shno, whenever appropriate].
I would like to tell STATA to look at the names of variables and execute;
tabstat `var', s(mean n max min med) c(s)
only for the set of variables that contains the same prefix, and
loop over the
next set of variables, and then next, and so on.
I tried to embed ifcmd or subinstr command in the loop but haven't been able
to pull it off. I feel like I'm missing out something very basic.
Thanks in advance for your help.
Yusuke
*
* 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/
*
* 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/