Yang Li wrote:
I have a huge list of variables in the form of
var1 par1 var2 par2 ... varN parN
I am intend to only copy var1, var 2.. var N to another stata file.
How can I realize this?
--------------------------------------------------------------------------------
There are a few different ways, depending upon how your variables are named.
If they're named with a numeric suffix, then -keep var*- (or -drop par*-),
and away you go.
On the other hand, if you're interested in keeping alternate variables, then
look into handling it with the aid of macros and loops (illustrated below).
Joseph Coveney
clear
set more off
input A a B b C c D d E e
1 2 3 4 5 6 7 8 9 0
end
foreach var of varlist _all {
local varlist `varlist' `var'
}
local keeplist
forvalues i = 1(2)`c(k)' {
local keepmember : word `i' of `varlist'
local keeplist `keeplist' `keepmember'
}
keep `keeplist'
list, noobs
save another_Stata_file
exit
*
* 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/