Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: passing indefinite no of arguments


From   tashi lama <ltashi32@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: passing indefinite no of arguments
Date   Wed, 4 Apr 2012 19:41:43 +0000

Thank you Nick for your time. I will read this weekend  and try again. 



----------------------------------------
&#62; Date&#58; Wed, 4 Apr 2012 20&#58;23&#58;02 &#43;0100&#13;&#10;&#62; Subject&#58; Re&#58; st&#58; passing indefinite no of arguments&#13;&#10;&#62; From&#58; njcoxstata&#64;gmail.com&#13;&#10;&#62; To&#58; statalist&#64;hsphsun2.harvard.edu&#13;&#10;&#62;&#13;&#10;&#62; No, sorry, that was quite wrong in part.&#13;&#10;&#62;&#13;&#10;&#62; Local macro 0 _is_ defined automatically as all the arguments to a&#13;&#10;&#62; do-file. However, in this case the two lines&#13;&#10;&#62;&#13;&#10;&#62; syntax anything&#13;&#10;&#62; tokenize &#96;anything&#39;&#13;&#10;&#62;&#13;&#10;&#62; don&#39;t do anything that can&#39;t be done in terms of macros &#96;1&#39; &#96;2&#39; &#96;3&#39; &#96;4&#39; up.&#13;&#10;&#62;&#13;&#10;&#62; On Wed, Apr 4, 2012 at 6&#58;54 PM, Nick Cox &#60;njcoxstata&#64;gmail.com&#62; wrote&#58;&#13;&#10;&#62; &#62; Tashi&#58;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; It is best to think that you are addressing Statalist, not any one person.&#13;&#10;&!
 #62; &#62;&#13;&#10;&#62; &#62; Evidently you have a do-file -file.do- but where it starts and ends is&#13;&#10;&#62; &#62; not clear from your code fragments below.&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; Evidently you are using -syntax- in a do-file which is not illegal but&#13;&#10;&#62; &#62; it is unusual. You need to understand that -syntax- looks inside the&#13;&#10;&#62; &#62; local macro 0, which apparently you never define. In a program,&#13;&#10;&#62; &#62; defined by code following a -program- statement, that is done&#13;&#10;&#62; &#62; automatically. However, &#96;1&#39; &#96;2&#39; etc. are defined in a do-file so your&#13;&#10;&#62; &#62; misunderstanding does not bite you. That is, the two lines&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; syntax anything&#13;&#10;&#62; &#62; tokenize &#96;anything&#39;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; do absolutely nothing but that does not invalidate your problem. On&#13;&#10;&#62; &#62; the other hand,&#13;&#10;&!
 #62; &#62;&#13;&#10;&#62; &#62; foreach x of &#225;varlist1 id&#42; &#

123;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; is illegal. You are confusing two quite different syntaxes&#58; examples are.&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; foreach x of local varlist1 &#123;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; foreach x of varlist id&#42; &#123;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; As I have tried to signal before, I advise against trying to write&#13;&#10;&#62; &#62; your own ranking code when Stata &#40;and Mata&#41; provide tools for sorting&#13;&#10;&#62; &#62; and ranking and there are existing programs to be exploited.&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; Nick&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; On Wed, Apr 4, 2012 at 4&#58;52 PM, tashi lama &#60;ltashi32&#64;hotmail.com&#62; wrote&#58;&#13;&#10;&#62; &#62;&#62; Hello Nick,&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; Could you pls look into my code below and tell me where is that I screwed although I feel like the code should work fine, at l!
 east in principle. Here is the dataset and the problem is of ranking ignoring few variables.&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62;&#62; date &#225; &#225; &#225; &#225; &#225; hits1 &#225; &#225; hits2 &#225; &#225; hits3 &#225; &#225; &#225;hits4 &#225; hits5&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; 01jan2010 &#225; &#225; &#225; 3 &#225; &#225; &#225; &#225; &#225;2 &#225; &#225; &#225; &#225;5 &#225; &#225; &#225; &#225; &#225;1 &#225; &#225; &#225; &#225; &#225;5&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; 02jan2010 &#225; &#225; &#225; 5 &#225; &#225; &#225; &#225; &#225;7 &#225; &#225; &#225; &#225;8 &#225; &#225; &#225; &#225; &#225;4 &#225; &#225; &#225; &#225; &#225;2&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; 03jan2010 &#225; &#225; &#225; 8 &#225; &#225; &#225; &#225; &#225;6 &#225; &#225; &#225; &#225;2 &#225; &#225; &#225; &#225; &#225;1 &#225; &#225; &#225; &#225; &#225;6&#13;&#10;&#62; &#62;&#62;&#13;&!
 #10;&#62; &#62;&#62; 04jan2010 &#225; &#225; &#225; 6 &#225; &#225; &#

225; &#225; &#225;5 &#225; &#225; &#225; &#225;3 &#225; &#225; &#225; &#225; &#225;2 &#225; &#225; &#225; &#225; &#225;7&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; 05jan2010 &#225; &#225; &#225; 6 &#225; &#225; &#225; &#225; &#225;4 &#225; &#225; &#225; &#225;2 &#225; &#225; &#225; &#225; &#225;6 &#225; &#225; &#225; &#225; &#225;7&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; 06jan2010 &#225; &#225; &#225; 1 &#225; &#225; &#225; &#225; &#225;5 &#225; &#225; &#225; &#225;3 &#225; &#225; &#225; &#225; &#225;7 &#225; &#225; &#225; &#225; &#225;8&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; if &#34;&#96;2&#39;&#34;&#61;&#61;&#34;rank&#34; &#225;&#123;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;syntax anything &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;!
  &#225; &#225;/&#42;allowing any data type to be passed. &#96;3&#39; and &#96;4&#39; are start_date and end_date&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;tokenize &#96;anything&#39;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;local para &#34;&#96;1&#39;&#34; &#34;&#96;2&#39;&#34; &#34;&#96;3&#39;&#34; &#34;&#96;4&#39;&#34; &#225; &#225; &#225;/&#42; breaking arguments into 2 macros &#96;para&#39; and &#96;deselected&#39; and putting first 4 arguments into &#96;para&#39; and rest into &#96;deselcted&#39;.&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;macro shift 4&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;local deselected &#34;&#96;&#42;&#39;&#34;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; unab all &#58; hits&#42!
 ;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; 

&#225; &#225; &#225; &#225; &#225; local varlist1 &#58; list all - deselected &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; /ignore variables from the list&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; di &#34;&#96; varlist1&#39;&#34; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;/displays the variables after ignoring. Works until this point.&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; rename hits&#42; id_&#42; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; /changing hits1 into id_1 and so on....&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; collapse &#40;sum&#41; id&#42; if tin&#40;&#96;3&#39;,&#96;4&#39;&#41; &#225; &#225; &#225; &#225; &#225; &#225; &#2!
 25; &#225; &#225; &#225; &#225; /summing providing date range&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; local counter 1&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;foreach x of &#225;varlist1 id&#42; &#123; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;/comparing and ranking&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;if &#96;x&#39;&#33;&#61;id_&#96;1&#39; &#38; &#96;x&#39;&#62;id_&#96;1&#39; &#123;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;local &#225;&#43;&#43;counter&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#2!
 25; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#2

25; &#225;&#125;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#125;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; list&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; di &#34;There are &#96;count&#39; firms in total and I rank &#96;counter&#39; &#34;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; exit&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225; &#225;&#125;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; Questions&#58;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; 1. When I ran&#!
 13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#225; &#225; &#225; &#225; do file 1 rank 01jan2010 02jan2010 hits3 hits4, there is an error which reads invalid syntax. I am not sure where I screwed.&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; 2. I supplied date range&#40;01jan2010-02jan2010&#41; for collapse sum, but it sums for all the dates &#40;01jan2010-06jan2010&#41;. Any idea&#63;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; 3. when I change the for loop as &#225; &#225; &#225; foreach x of local varlist1 &#225;and run it, I get hits1 not found. So, it is still taking hits1 as the first variable in the varlist1. But I thougnt everything in varlist1 starts with id_ since I renamed them. Could you pls explain&#63;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#225;Thank you very much and I really appreciate your time...&#13;&#10;&#62; &#62;&!
 #62;&#13;&#10;&#62;&#13;&#10;&#62; &#42;&#13;&#10;&#62; &#42; For sear

ches and help try&#58;&#13;&#10;&#62; &#42; http&#58;//www.stata.com/help.cgi&#63;search&#13;&#10;&#62; &#42; http&#58;//www.stata.com/support/statalist/faq&#13;&#10;&#62; &#42; http&#58;//www.ats.ucla.edu/stat/stata/&#13;&#10; 		 	   		  
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index