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]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Converting text file to Stata data file |

Date |
Mon, 1 Oct 2012 20:22:58 +0100 |

This is what -infix- is all about. Alternatively, I'd consider reading this in as a string variable. Let's suppose that there are blocks of 20 lines each. infile str40 mystr replace mystr = trim(mystr) compress egen block = seq(), block(20) egen line = seq(), to(20) reshape wide mystr, i(block) j(line) destring mystr*, replace Nick On Mon, Oct 1, 2012 at 7:52 PM, Michael Eisenberg <meisenberg713@gmail.com> wrote: > I have a question regarding importing a text file into Stata. In many > ways, it's a follow up question to an earlier question I asked where I > needed to convert data from Stata into a text file with specific > information in designated character line positions. > > Before the format assumed 100 characters per line. Where () represents > which line characters are assigned to a given field. > > (1-20) LAST NAME > (21-35) FIRST NAME > (36) MIDDLE INITIAL > (37-45) SSN > (46-47) MONTH OF BIRTH > etc > > In this case, outfixt was the brilliant answer. > > I now have an output file in a similar format and I need to convert it > back into a Stata data file. Is there a similar command that can > convert a text file into a Stata data file where the user can > designate which columns correspond to individual fields? On Tue, Jan 17, 2012 at 7:05 AM, Austin Nichols <austinnichols@gmail.com> wrote: >> replace lastname=substr(lastname,1,20) >> *etc, then: >> ssc install outfixt On Tue, Jan 17, 2012 at 9:56 AM, Michael Eisenberg >>> I have to prepare a file for a linkage project, and I’m hoping stata can assist. >>> >>> Currently my data is in a stata data file. >>> >>> The linkage company requires a set format of data in a plain text format. >>> >>> The format assumes 100 characters per line. Where () represents which >>> line characters are assigned to a given field. If a variable has >>> more characters than the designated number of characters, it is to be >>> truncated >>> >>> (1-20) LAST NAME >>> (21-35) FIRST NAME >>> (36) MIDDLE INITIAL >>> (37-45) SSN >>> (46-47) MONTH OF BIRTH >>> (48-49) DAY OF BIRTH >>> (50-53) YEAR OF BIRTH >>> >>> The data currently looks like this >>> >>> Lastname firstname middlename SSN MonOB DaOB YrOB >>> Smith John Thomas 122342789 01 04 1947 >>> Jones Craig Harvey 600656785 10 24 1957 >>> Stata Jim Smith 423456751 12 06 1970 >>> Johnson Mike Thomas 056445671 01 16 1971 >>> >>> Can Stata perform such a transformation? If not, are there other >>> programs that could be recommended. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Converting text file to Stata data file***From:*Michael Eisenberg <meisenberg713@gmail.com>

- Prev by Date:
**Re: st: cascading dummies** - Next by Date:
**st: separating components of a string variable** - Previous by thread:
**st: Converting text file to Stata data file** - Next by thread:
**st: separating components of a string variable** - Index(es):