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]

AW: st: AW: Counting months over several years in a variable


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: AW: Counting months over several years in a variable
Date   Sat, 29 May 2010 16:50:46 +0200

<> 

Ok, this kind of problem can be solved via -egen, group()-



*************
clear*

inp int Year byte month
2008       8            
2008       8
2008       8
2008       9         
2008       9
2008      10   
2008      10
2008      11
2008      11          
2008      12        
2009       1            
2009       1
2009       2           
2009       3
2009       3            
end

egen myvar=group(Year month)

list, sepby(Year month) noo
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von George Chioran
Gesendet: Samstag, 29. Mai 2010 16:35
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: AW: Counting months over several years in a variable

Sorry, i forgot to mention that there are in total over 100 000 observations, over a period of 1,5 years, so myvar can only take 18 distinct values at maximum. 
There are a lot of duplicates in the database like this:


Year      month  mvar
2008    8            1
2008 81
200881
2008      9         2
200892
200810   3
2008103
2008114
2008      11          4
2008      12        5
20091            6
200916
2009      2            7
200938
2009      3            8
…            …            …


----- Original Message ----
From: Martin Weiss <martin.weiss1@gmx.de>
To: statalist@hsphsun2.harvard.edu
Sent: Sat, May 29, 2010 3:51:52 PM
Subject: st: AW: Counting months over several years in a variable


<> 

So this code -generate-s "myvar" across the entire dataset. Make sure it does what you want:

*************
clear*

inp int Year byte month 
2008       8    
2008       9    
2008       10    
2008       11    
2008       12    
2009       1    
2009       2    
2009       3 
end

gen myvar=_n
list, noo

*************



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von George Chioran
Gesendet: Samstag, 29. Mai 2010 15:07
An: statalist@hsphsun2.harvard.edu
Betreff: st: Counting months over several years in a variable

Dear statalisters, 

I want to count the
months in several years. I have variables year and month, and want to obtain
variable mvar. My database looks like this. 

Year       month  mvar
2008       8             1
2008       9             2
2008       10     3
2008       11           4
2008       12           5
2009       1             6
2009       2             7
2009       3             8
…             …             …

Thank you in advance
for your help, 
George


      

*
*   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/


*
*   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/



      

*
*   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/


*
*   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