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: syntax and gettoken with parentheses and equal signs


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: syntax and gettoken with parentheses and equal signs
Date   Thu, 27 Mar 2014 14:43:00 +0100

On Thu, Mar 27, 2014 at 2:15 PM, Eric Lewis wrote:
> 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.
>
>
> program test_parentheses
>      * example syntax y z1 z2 z3 (x1 x2 = z4 z5)

*------------------ begin example ------------------
local anything "y z1 z2 z3 (x1 x2 = z4 z5)"

// get the dependent variable
gettoken lhs rest : anything
di "`lhs'"
di "`rest'"

// get exogenous vars
gettoken exog rest : rest, parse("(")
di "`exog'"
di "`rest'"
gettoken open rest : rest, parse("(")
di "`rest'"

// get endogenous vars
gettoken endog rest : rest, parse("=")
gettoken equal rest : rest, parse("=")
di "`endog'"
di "`rest'"

// get instruments
gettoken inst close : rest, parse(")")
di "`inst'"
di "`close'"
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )

I would than make heavy use of -fvunab- or -unab-, -confirm-, and
-_fv_check_depvar-, to check if the user made any mistakes while
specifying the syntax.

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   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