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]

st: is there a way to determine variable storage type within a dofile

From   "Sarah Edgington" <>
To   <>
Subject   st: is there a way to determine variable storage type within a dofile
Date   Fri, 9 Dec 2011 15:52:48 -0800

Hello all,

Is there a way to get Stata to return the storage type for a variable?  I
know I can use -describe- to visually see the storage type, but I would like
to use the information in an if statement as part of a loop.  Basically, I
guess I'm looking for something conceptually like the isreal function in

I am working on importing and cleaning some data that began its life as an
Excel spreadsheet.  I have a series of columns in the original sheet that
either have an X in them or are blank and I'm trying to turn these into
zero-one indicators in my final dataset.  So I'm using -foreach- to loop
through the varlist of each of these indicator variables, changing X to 1
and missing to zero, then using -destring- to create the final desired byte
variable.  The problem is that sometimes a column has no Xs and gets
imported as a byte variable (with all observations missing).  So when I get
to those variables my loop exits due to type mismatch.  I can work around
this with capture but this is not the first time for this project that I've
found myself thinking that I want to do a particular thing just with string
variables or just numeric variables.  If I were only importing the data once
I'd just do it the hard way and make a list of the string variables by hand,
but since I'm setting up dofiles to read in new files as we get them, I
anticipate that exactly which variables get imported with which storage
types will change over time.  In general it seems like I might be able
construct cleaner and more manageable code if there were some command that
would return the storage type for a variable that I could use to create
lists of variables of a given type.  Or is there some other obvious trick
I'm missing that would make constructing this type of code easier?


-Sarah Edgington

*   For searches and help try:

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