Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65569

How can I check that a variable exists?

$
0
0
Dear StataList,

I have a fairly simply task that I'd appreciate help with. I'm trying to write a block of code that will work on a number of different datasets. I'd like the code to put the variables in a certain order. The issue is that in some of the datasets one or more of the variables is missing. A similar question was asked before but I haven't been able to modify the solution properly. This is the code that I'm using.


sysuse auto
local vars "foreign gear_ratio missing"

foreach var in `vars'{
capture confirm variable `vars'
if !_rc {
order `vars'
}
}


The code only works if all the variables are in the dataset. I'm using Stata 11.

Thanks for your help,
Wilfred

Viewing all articles
Browse latest Browse all 65569

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>