Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: Number of a subset of variables in local

From   Antoine Terracol <>
Subject   Re: st: Number of a subset of variables in local
Date   Thu, 19 Aug 2010 15:11:34 +0200

unab mylist : name*
display "`mylist'"


On 19/08/2010 15:04, Trelle Sven wrote:
Dear all,
I have a dataset with several variables all starting with the same name
plus sequential numbers at the end (e.g. name1, name2, name3, ...). In
addition, there are several other variables. I want to put the number of
variables starting with "name" in a local. Originally I thought I can

describe name*

But apparently, the describe command puts the number of variables of the
whole dataset in r(k) and not just the number of variables specificied
after the command.

This is my workaround:

* example starts
  use datatset.dta, clear
  keep name*
  qui describe
  local n = r(k)
  use datatset.dta, clear
* Example ends

Does anybody know whether there is a more elegant way i.e. can I avoid
loading the dataset twice?

Thanks for your help

*   For searches and help try:

Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.

*   For searches and help try:

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