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: RE: changing observations under one variable


From   Rudy Hover <rudy.hover@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: changing observations under one variable
Date   Tue, 24 Apr 2012 16:33:23 +0200

Thank you Nick. 
The reason I want to change the data is that I need to merge it with a dataset that contains the dates in the '199901' format. 

Because of that just displaying the data in another way won't help me out in the end. 

I used your tip to generate a variable that is just year and month
gen monthdate=mofd(date)

So now for instance 29jan1999 becomes 468 (do you know why 468?)

However if the underlying cell is in the format '199901' then the operator
gen monthdate=mofd(date)
creates a value for 199901 that equals 6567.

So then I have a mismatch, since both 29jan1999 and 199901 should be be replaced/used to create the same (new) value.

How can I let stata perform this?


On Apr 24, 2012, at 3:39 PM, Nick Cox wrote:

> You can apply a different -format- to get a display of just year and month. 
> 
> . di %tdCCyyNN mdy(4,24,2012)
> 201204
> 
> You can get a date variable that is just year and month by using -mofd()- as in 
> 
> gen monthdate = mofd(date) 
> 
> . di %tm mofd(mdy(4,24,2012))
> 2012m4
> 
> This is all documented. 
> 
> Nick 
> n.j.cox@durham.ac.uk 
> 
> Rudy Hover
> 
> The variable 'date' has type -long-.
> 
> The format is -%d-
> 
> The label is -Date of Observation-
> 
> 
> On Apr 24, 2012, at 2:08 PM, Nick Cox wrote:
> 
>> The word format means so many things! "29jan1999" is not a format in the sense of -format-. It might the result of setting a particular format? 
>> 
>> Is -date- a string variable? Is it a numeric variable with a date format assigned. 
>> 
>> Do you want another string variable? Do you want a numeric variable with a specified display -format-? 
>> 
>> Nick 
>> n.j.cox@durham.ac.uk 
>> 
>> Rudy Hover
>> 
>> I have one variable called 'date' with observations in the format '29jan1999' until '19dec2006', so the last working day of the month, the month and then the year. I want to change this to the format '199901' or '200612', so I don't need the day anymore, only the year and then the month. Could you help me how to replace?
>> 
> 
> *
> *   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