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: Expanding date ranges that are stored as strings


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Expanding date ranges that are stored as strings
Date   Fri, 28 Oct 2011 08:32:59 +0100

Assume a variable -country- and -mydate- with values like

"1999"
"1993-2001"

If that is it, you don't need anything fancy:

gen first = real(substr(date,1,4))
gen second = real(substr(date,6,.))
gen length = second-first+ 1
expand length if !missing(length)
bysort country first : replace first = first[1] + _n - 1
replace date = first
drop second

If the form of -mydate- is more complicated, extract the dates with
-moss- (SSC). (Several mentions on the list, especially over the last
week.)

This does nothing about interpolation of the other key variables,
which may be your real problem.

Nick

On Fri, Oct 28, 2011 at 5:30 AM, Anthony Hong <anthony.hong@gmail.com> wrote:

> I'm having a bit of a problem.  I'm using the UNU-WIDER dataset which
> reports countries and various years.  The problem is that while some
> years are recorded as say 1999, 2000, there are some that are recorded
> as ranges, for example 1993- 2001.
>
> I would like to take these date ranges and generate individual
> observations for each year within the range.  I am unsure how I would
> identify parts of the string in order to identify how many
> observations to fill in.

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