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 at the end of May, and its replacement, statalist.org is already up and running.


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

RE: st: ranking variables on the basis of total values of observations


From   tashi lama <ltashi32@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: ranking variables on the basis of total values of observations
Date   Thu, 29 Mar 2012 14:56:33 +0000

Thanx Nick,

    I think I resolved. Thanks for your time. 

 

Tashi

----------------------------------------
&#62; Date&#58; Thu, 29 Mar 2012 15&#58;52&#58;24 &#43;0100&#13;&#10;&#62; Subject&#58; Re&#58; st&#58; ranking variables on the basis of total values of observations&#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; This is your problem and you can make it as difficult as you wish.&#13;&#10;&#62;&#13;&#10;&#62; What I recommend is that you calculate whatever you want as totals and&#13;&#10;&#62; then make those totals data &#40;meaning, values of variables&#41; before&#13;&#10;&#62; passing them to -rowranks-. For example, you can use -sum&#40;&#41;- to get&#13;&#10;&#62; cumulative sums and then pass those you want to -rowranks- or you can&#13;&#10;&#62; -collapse- first.&#13;&#10;&#62;&#13;&#10;&#62; Note that nothing stops you calling -rowranks- with just a single observation.&#13;&#10;&#62;&#13;&#10;&#62; On the other hand it is open to you to write your own program and/or&#13;&#10;&!
 #62; modify -rowranks- so that everything is included in your own code.&#13;&#10;&#62;&#13;&#10;&#62; Nick&#13;&#10;&#62;&#13;&#10;&#62; On Thu, Mar 29, 2012 at 3&#58;02 PM, tashi lama &#60;ltashi32&#64;hotmail.com&#62; wrote&#58;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; Yes, it does look like a rowranks problem but i think it is lil deeper because I have a time series data and I want to be able to provide time range. So, if you look at the following dataset, rowranks will give me a rank for each row.. But that is not exactly what I want. I want to be able to rank not only for 05jan2010, 06jan2010 and so on but 05jan2010-08jan2010. Now, in order to this, I have to be able to sum the values from 05jan2010-08jan2010 for all var1 var2 and var3 like given below. If I can do that, there would be only one row where obs are the sum. If i can do that, I can use rowranks. So,&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; date totalvar2 totalvar!
 3 totalvar4&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; 05jan2010-08jan2

010 10 10 22&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; Yes, now I could use rowranks. Ahh...actually this analogy might make things clear. You know how when you graph pie, you could give do sth like&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; graph pie var1 var2 if tin&#40;05jan2010, 08jan2010&#41;, plabel&#40;_all percent&#41; &#61;&#62; stata will sum the values of obs for both var1 and var2 for that period and compute the percentage. Rowranks doesn&#39;t allow ifs looking at the syntax.&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; Let me know if I could make any clearer.&#13;&#10;&#62; &#62;&#13;&#10;&#62; &#62; Thanking and really appreciating your time and wisdom,&#13;&#10;&#62;&#13;&#10;&#62; &#62;&#62; Date&#58; Wed, 28 Mar 2012 23&#58;22&#58;15 &#43;0100&#13;&#10;&#62; &#62;&#62; Subject&#58; Re&#58; st&#58; ranking variables on the basis of total !
 values of observations&#13;&#10;&#62; &#62;&#62; From&#58; njcoxstata&#64;gmail.com&#13;&#10;&#62; &#62;&#62; To&#58; statalist&#64;hsphsun2.harvard.edu&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; If I understand your problem correctly, it is that of -rowranks-.&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; See also for a review in that territory&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; SJ-9-1 pr0046 . . . . . . . . . . . . . . . . . . . Speaking Stata&#58; Rowwise&#13;&#10;&#62; &#62;&#62; &#40;help rowsort, rowranks if installed&#41; . . . . . . . . . . . N. J. Cox&#13;&#10;&#62; &#62;&#62; Q1/09 SJ 9&#40;1&#41;&#58;137--157&#13;&#10;&#62; &#62;&#62; shows how to exploit functions, egen functions, and Mata&#13;&#10;&#62; &#62;&#62; for working rowwise&#59; rowsort and rowranks are introduced&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; This is now accessible to all at&#13;&#10;&#62; &#62;&#62; http&#58;//www.stata-journal.com/sjpdf.html&#63!
 ;articlenum&#61;pr0046&#13;&#10;&#62; &#62;&#62; under the Stata Journ

al&#39;s three-year window.&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; Nick&#13;&#10;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; On Wed, Mar 28, 2012 at 9&#58;44 PM, tashi lama &#60;ltashi32&#64;hotmail.com&#62; wrote&#58;&#13;&#10;&#62; &#62;&#62; &#62; Hello Nick,&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62; My apology, I mean rowranks, not rowsum. So, let&#39;s see if I could simplify it...&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62; Essentially I want to be able to rank var2 in the following dataset looking at its total values of obs from 05jan2010 to 09jan2010. so, I would use generate sum to get a rumsum. That would look like&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62; date var2 var3 var4 totalv&#126;2 totalv&#126;!
 3 totalv&#126;4&#13;&#10;&#62; &#62;&#62; &#62; 1. 05jan2010 3 1 7 3 1 7&#13;&#10;&#62; &#62;&#62; &#62; 2. 06jan2010 2 3 6 5 4 13&#13;&#10;&#62; &#62;&#62; &#62; 3. 07jan2010 4 4 5 9 8 18&#13;&#10;&#62; &#62;&#62; &#62; 4. 08jan2010 1 2 4 10 10 22&#13;&#10;&#62; &#62;&#62; &#62; 5. 09jan2010 5 8 3 15 18 25&#13;&#10;&#62; &#62;&#62; &#62; 6. 10jan2010 8 9 2 23 27 27&#13;&#10;&#62; &#62;&#62; &#62; 7. 11jan2010 4 6 3 27 33 30&#13;&#10;&#62; &#62;&#62; &#62; 8. 12jan2010 3 3 8 30 36 38&#13;&#10;&#62; &#62;&#62; &#62; 9. 13jan2010 1 2 3 31 38 41&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62; So, I would look at the observations at 09jan2010. So, as you can see, var2 has 5, var3 has 8 and so on. since 5 is the second lowest in that row after 3, I would say var2 is 2nd. Now, I have to able to code this and that is exactly I think you guys can help me or give me a lead!
 .&#13;&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#13;

&#10;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62; Thank you and let me know if I could make more clea.&#13;&#10;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; Date&#58; Wed, 28 Mar 2012 21&#58;17&#58;19 &#43;0100&#13;&#10;&#62; &#62;&#62; &#62;&#62; Subject&#58; Re&#58; st&#58; ranking variables on the basis of total values of observations&#13;&#10;&#62; &#62;&#62; &#62;&#62; From&#58; njcoxstata&#64;gmail.com&#13;&#10;&#62; &#62;&#62; &#62;&#62; To&#58; statalist&#64;hsphsun2.harvard.edu&#13;&#10;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; I don&#39;t know what -rowsum- is here.&#13;&#10;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; Thanks, but this doesn&#39;t get me much closer. Of course, if other&#13;&#10;&#62; &#62;&#62; &#62;&#62; people can work out what you want, they should chip in.&#13;&#10;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; Please _show_ what you want it changed to, as I asked earlier. No!
 &#13;&#10;&#62; &#62;&#62; &#62;&#62; word description, just what the dataset would like look after changes.&#13;&#10;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; Nick&#13;&#10;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; On Wed, Mar 28, 2012 at 8&#58;49 PM, tashi lama &#60;ltashi32&#64;hotmail.com&#62; wrote&#58;&#13;&#10;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62; date var2 var3 var4&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62; 1. 05jan2010 3 1 7&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62; 2. 06jan2010 2 3 6&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62; 3. 07jan2010 4 4 5&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62; 4. 08jan2010 1 2 4&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62; 5. 09jan2010 5 8 3&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62; 6. 10jan2010 8 9 2&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62; 7. 11jan2010 4 6 3&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62; 8. 12jan2010 3 3 8&#13;&#10;&#62; &#62;&#62; &#62;&#62;!
  &#62; 9. 13jan2010 1 2 3&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#

13;&#10;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62; Say, I would like to rank var2 for certain period of time say &#40;05jan2010-09jan2010&#41;. So, I would have Stata add the obs values from 05jan2010 to 09jan2010 for all the variables and rank var2 like 1st or 2nd or 3rd. I looked at rowsum. I don&#39;t think it will help.&#13;&#10;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; Date&#58; Wed, 28 Mar 2012 20&#58;34&#58;58 &#43;0100&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; Subject&#58; Re&#58; st&#58; ranking variables on the basis of total values of observations&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; From&#58; njcoxstata&#64;gmail.com&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; To&#58; statalist&#64;hsphsun2.harvard.edu&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; As far as I can see this could mean several things. I am not clear&#13;&#10;&#62; &#62!
 ;&#62; &#62;&#62; &#62;&#62; that when you say &#34;rank&#34; you don&#39;t mean &#34;order&#34; instead.&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; I don&#39;t think you want -rowranks- &#40;SSC&#41;.&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; Why not just give us a toy dataset, with say 5 observations and 5&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; variables, and what you want to change it to&#63; Then it should be easier&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; to see what you want.&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; By the way, adding lots of blank lines just makes your posts more&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; difficult to read. I&#39;ve edited what came in.&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; Nick&#13;&#10;&#62; &#6!
 2;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#6

2;&#62; On Wed, Mar 28, 2012 at 8&#58;22 PM, tashi lama &#60;ltashi32&#64;hotmail.com&#62; wrote&#58;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62; I have a list of variables and I would like to rank the variables or any given variable for that matter on the basis of total values of their observations. I thought of approaching this problem in the following way.&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62; 1. find the running sum of all the variables using generate or the total using egen although I think I would prefer generate.&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62; say there are var1 var2 var3&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62; gen tvar1&#61;sum&#40;var1&#41;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62!
 ; gen tvar2&#61;sum&#40;var2&#41;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62; gen tvar3&#61;sum&#40;var3&#41;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62; 2. then compare tvar1, tvar2 and tvar3 using if conditions.&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62; Once this is done, I would like to expand such that I can rank those variables but for given period of time. And this is essentially why I think generate sum is better for this problem because it is a running sum.&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62; say date var1 var2 var3&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62;&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62; I would like to be able to rank variables say for 01jan2011 to 01feb2011 and so on.&#13;&#10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62;&#13;&#!
 10;&#62; &#62;&#62; &#62;&#62; &#62;&#62; &#62; Has anyone worked in t

his kind of problem before or does anyone have any idea or thought regarding this problem&#63; Any help or lead would be highly appreciated&#63; I saw that there is a stata module rowranks to calculate ranks in a row but i don&#39;t know how can it be useful to me. Most probably not....&#13;&#10;&#62;&#13;&#10;&#62; &#42;&#13;&#10;&#62; &#42; For searches 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