11.07.2015 Views

[U] User's Guide

[U] User's Guide

[U] User's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

224 [ U ] 18 Programming Stata‘varlist’‘if’‘in’the two or more variable namesthe if exp specified by the user (or nothing)the in range specified by the user (or nothing)To see that this works, experiment with the following program:Below we experiment:program tryitsyntax varlist(min=2) [if] [in]display "varlist now contains |‘varlist’|"display ‘"if now contains |‘if’|"’display "in now contains |‘in’|"end. tryit mpg weightvarlist now contains |mpg weight|if now contains ||in now contains ||. tryit mpg weight displ if foreign==1varlist now contains |mpg weight displ|if now contains |if foreign==1|in now contains ||. tryit mpg wei in 1/10varlist now contains |mpg weight|if now contains ||in now contains |in 1/10|. tryit mpgtoo few variables specifiedr(102);In our third try we abbreviated the weight variable as wei, yet, after parsing, syntax unabbreviatedthe variable for us.If this program were next going to step through the variables in the varlist, the positional macros‘1’, ‘2’, . . . could be reset by codingtokenize ‘varlist’See [P] tokenize. tokenize ‘varlist’ resets ‘1’ to be the first word of ‘varlist’, ‘2’ to bethe second word, and so on.18.4.5 Parsing immediate commandsImmediate commands are described in [U] 19 Immediate commands—they take numbers asarguments. By convention, when you name immediate commands, you should make the last letterof the name i. Assume that mycmdi takes as arguments two numbers, the first of which must be apositive integer, and allows the options alpha and beta. The basic structure isprogram mycmdigettoken n 0 : 0, parse(" ,") /* get first number */gettoken x 0 : 0, parse(" ,") /* get second number */confirm integer number ‘n’ /* verify first is integer */confirm number ‘x’ /* verify second is number */if ‘n’

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!