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: database manipulation


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
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. 

Nick 
n.j.cox@durham.ac.uk 

Eric Booth

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

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