Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: parsing question

From   "Tom Boonen" <>
Subject   st: parsing question
Date   Thu, 8 Mar 2007 21:52:27 -0500


I am fairly new to Stata programming and have a question regarding the
best way to use the syntax command to parse user input into macros so
I can work with them in my program.

In my estimation command, the user enters a response variable Y and
several predictor variables X1 X2 X3.

so this is easy to parse using

syntax varlist
gettoken depvar varlist: varlist

So the user would code:

command Y X1 X2 X3

Now, I also would like to give the user the possibility to specify for
each predictor a numlist of periods over which the predictor shall be
used in the estimation (this is kind of unusual, but makes sense in my
particular estimation). So the user would code something like:

command Y X1 X2(1980(1)2000) X3(1998 1990)

which would mean that X1 would be used for all years. X2 would be used
for years 1980,1981,...,2000 and X3 would be used for years 1998 and
1990 only. I wonder what would be the best way to parse this. I was

syntax anything

gettoken depvar varlist: varlist

then i would need to loop through each element of varlist, look for
the first "(" , obtain the numbers after the "(", look for the next
")", store the number in front of it. etc etc etc.

this seems a bit tedious and error prone (the user may put an extra
blank or number here and there). i wonder whether there is any better
way to parse this?

any help is appreciated.


gettoken depvar varlist: varlist


but for each predictor the user may specify a ceratin time period
over which the respective predictor is averaged.
*   For searches and help try:

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