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: syntax and gettoken with parentheses and equal signs
From
daniel klein <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: syntax and gettoken with parentheses and equal signs
Date
Thu, 27 Mar 2014 14:41:10 +0100
Eric,
let me sketch two possible approaches
pr foo
vers 12.1
// first split into lhs exog endog
gettoken lhs 0 : 0
gettoken exog 0 : 0 ,p("(")
gettoken endog 0 : 0 ,bind
// further parse endog
gettoken endog inst : endog ,p("=")
gettoken eqs inst : inst ,p("=")
syntax [if] [in] [, *]
<...>
end
You could also do
pr foo
vers 12.1
// get part before parentheses
gettoken left 0 : 0 ,p("(")
// get part in parentheses
gettoken right 0 : 0 ,bind
// now parse the two parts
gettoken lhs exog : left
gettoken endog exog : right ,p("=")
gettoken equalsign exog : exog ,p("=")
syntax [if] [in] [, *]
<...>
end
You want to check for various vital errors that might occur (e.g. user
forgets to type parentheses, specifies names that are not variables in
the current dataset etc.) and you will have to decide how to that.
Best
Daniel
--
Dear Statalist
I am trying to write an IV-type estimator that allows for parentheses
(for the first stage regression). I understand that gettoken with the
"bind" option can help with parentheses. However I am having a hard
time implementing that in practice. How can I use gettoken and/or
syntax in this setting?
e.g., I want a program that can define the macros lhs, exog, endog,
and inst based on arguments and the position of parentheses and the
equal sign.
[...]
Currently I am taking the easy way out and using many options:
syntax [if] [in], lhs(varname) exog(varlist) endog(varlist) inst(varlist)
*
* 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/