Stata 11 help for confirm

help confirm -------------------------------------------------------------------------------

Title

[P] confirm -- Argument verification

Syntax

confirm existence string

confirm [new] file filename

confirm [ numeric | string | date ] format string

confirm names names

confirm [integer] number string

confirm matrix string

confirm scalar string

confirm [ new | numeric | string | type ] variable varlist [, exact]

where type is { byte | int | long | float | double | str# }

Description

confirm verifies that the arguments following confirm ... are of the claimed type and issues the appropriate error message and nonzero return code if they are not.

confirm is useful in do-files and programs when you do not want to bother issuing your own error message. confirm can also be combined with capture to detect and handle error conditions before they arise; see [P] capture.

See [P] confirm for a complete description of this command.

Option

exact specifies that a match be declared only if the names specified in varlist match. By default, names that are abbreviations of variables are considered to be a match.

Examples

. confirm file `"c:\data\mydata.dta"'

. confirm numeric variable price trunk rep78

You are writing a command that performs some action on each of the variables in the local macro varlist. The action should be different for string and numeric variables. The confirm command can be used here in combination with the capture command to switch between the different actions:

foreach v of local varlist { capture confirm string variable `v' if !_rc { action for string variables } else { action for numeric variables } }

An alternative solution using inline expansion of the extended macro function :type (see local) reads

foreach v of local varlist { if substr("`:type `v''",1,3) == "str" { action for string variables } else { action for numeric variables } }

Also see

Manual: [P] confirm

Help: [P] capture


© Copyright 1996–2009 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index