Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

RE: st: database manipulation

From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: database manipulation
Date   Fri, 8 Oct 2010 11:01:22 +0100

1/1/75 is an ambiguous example, but "DMY" is an alternative argument should "MDY" not be correct. (Using "DMY" is very common in the UK, for example. Always try to remember that this is an international list.) 

Also, let me underline what the help explains: -split- is smart enough to be able to parse on spaces and commas simultaneously, although watch out for examples like "College Station, TX". 

In practice, I would parse on commas first; and if that yields only one non-empty substring parse that single string on spaces. 

[email protected] 

Eric Booth

**input some fake data**
inp str12(date site)
"12/3/1979" "Dallas, TX"
"1/1/1975" "Houston,TX"

g date2 = date(date, "MDY")
format date2 %td
help dates_and_times

**sep city and state**
split site, p(",")
help split

**use trim() function to get rid of extra spaces**
replace site1 = trim(site1)
replace site2 = trim(site2)
help f_trim

On Oct 7, 2010, at 3:40 PM, Michael Eisenberg wrote:

> I have what I hope are a few simple questions regarding a fragmented
> database I'm trying to manipulate in stata.
> 1. Is there a way to convert the following date format (1/1/1975) into
> a date form that stata will recognize?
> 2.  Is it possible to separate a single string field separated by
> commas into 2 separate fields (i.e. Dallas, TX into Dallas in one
> field and TX in another)?  What about if a space was between the two
> fields (i.e. Dallas TX into two fields - one with Dallas and the other
> with TX)?

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index