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: use of subinstr


From   Eric Booth <[email protected]>
To   [email protected]
Subject   Re: st: use of subinstr
Date   Thu, 22 Mar 2012 16:52:51 -0500

<>

On Mar 22, 2012, at 4:30 PM, Nick Cox wrote:

> Eric's code should crack the problem nicely. I add some detailed comments:
> 
> 1. for N in num 1/100: g varN = runiform() //old school 1 line loop
> 
> I recommend against recommending old commands that are now
> undocumented. This should be in any Stata >= 7
> 
> forval N = 1/100 {
>     g var`N' = runiform()
> }
> 


As always, thanks Nick.  The use of the old -for- command was just for fun; I guess I should put a disclaimer about it being undocumented (or avoid using it on SL).  (I only recently discovered it in reading your 2003 (vol 3, num 2) SJ article and thought it was interesting to toy with). 


> 2. On
> ds var*
> local varlist `r(varlist)'
> di `"`varlist'"'
> foreach x of local varlist {
> 
> What follows is more direct. -ds- is several dozen lines of code to
> interpret. All you want to do is expand the wildcard. See also Stata
> Journal 10(3): 503-4. Stata tip 91: Putting unabbreviated varlists
> into local macros
> unab varlist : var *
> foreach x of local varlist {
> 
> Nick


Yes - I was echoing Tashi's code - and another way to do it could be:

foreach x of varlist var* {
   **code here**
   }	

((which is probably in your SJ article you recommend (but it's behind the paywall for me))).

- Eric

__
Eric A. Booth
Public Policy Research Institute 
Texas A&M University
[email protected]
+979.845.6754


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index