Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Maarten Buis <maartenlbuis@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Wishlist for Stata 13 |
Date | Wed, 30 Jan 2013 14:50:53 +0100 |
On Wed, Jan 30, 2013 at 2:17 PM, Richard Goldstein wrote: > a big (to me) caveat to the -defv- solution (and also to Maarten Buis' > solution from today): it does not work with -egen- and it does not work > with -by- Here are the solutions: *! version 1.0.0 30Jan2013 MLB program define myegen, byable(onecall) if "`_byvars'" != "" { local byby "by `_byvars' : " } `byby'egen `0' // find the name of variable gettoken x rest : 0 local type "byte int long float double" if `: list x in type' { gettoken x : rest } gettoken x : x, parse("=") // add note note `x' : `byby'egen `0' end *! version 1.0.0 30Jan2013 MLB program define mygen, byable(onecall) if "`_byvars'" != "" { local byby "by `_byvars' : " } `byby'generate `0' // find the name of variable gettoken x rest : 0 local type "byte int long float double" if `: list x in type' { gettoken x : rest } gettoken x : x, parse("=") gettoken x : x, parse(":") // add note note `x' : `byby'generate `0' end *! version 1.0.0 30Jan2013 MLB program define myreplace, byable(onecall) if "`_byvars'" != "" { local byby "by `_byvars' : " } `byby'replace `0' // find the name of variable gettoken x rest : 0 local type "byte int long float double" if `: list x in type' { gettoken x : rest } gettoken x : x, parse("=") // add note note `x' : `byby'replace `0' end 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/