Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: dropvars.ado


From   Joerg Luedicke <[email protected]>
To   [email protected]
Subject   Re: st: dropvars.ado
Date   Tue, 15 Jan 2013 17:07:06 -0500

Perhaps something like this?

*----------------------------------------------------
cap program drop dropva
program define dropva

syntax namelist

local wc : word count `namelist'

local vlist1=""
local vlist2=""

forval i=1/`wc' {
	local var : word `i' of `namelist'
	cap confirm var `var'
	if !_rc {
		loc vlist1 `vlist1' `var'
	}
	else {
		loc vlist2 `vlist2' `var'
	}
}

cap drop `vlist1'

if "`vlist2'"!="" {
	di in red "Warning, " as txt "the following variables are not found:"
	di as res "`vlist2'"
}

end
*----------------------------------------------------

sysuse auto, clear
dropva headroom trunk foo

Joerg

On Tue, Jan 15, 2013 at 5:01 PM, Dimitriy V. Masterov
<[email protected]> wrote:
> Austin,
>
> Thanks for taking a stab at this. However, this won't quite work as I
> would like. I would like to drop variables when they exist, and ignore
> when they don't (and maybe with an error message). Your code will not
> work with phantom variables.
>
> DVM
>
>
>
> On Tue, Jan 15, 2013 at 1:49 PM, Austin Nichols <[email protected]> wrote:
>>
>> prog dropvars2
>> syntax [varlist]
>> version 6
>> for var `varlist': capture drop X
>> end
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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