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: using infile dictionary


From   Jon Gettman <jgettman@hughes.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: using infile dictionary
Date   Sat, 24 Jul 2010 16:29:21 -0400

Andrzej,

Jeph Herrin earlier wrote that "Sometimes the best solution isn't a Stata solution; for this kind of problem I usually invoke some other software." That might be a useful approach here. If I understand you correctly you have 6 blocks of data in a vertical sequence and you want them horizontal. Open the file in Excel. Block 1 is line A1 through 123. Block 2 is line A124 through B247. Cut out block 2 and paste it into C1:D123 . Do the same for blocks 3,4,5 and 6 into columns E&F, G&H, I&J, and K&L respectively. If the text line is unnecessary on Stata, delete row 1. Insert a blank row at the top, enter some var names, save it as a text file, and import to Stata via the insheet command. Sometimes brute force is easier than elegance. It's often better to solve the problem in an elegant way because you learn something that becomes useful later. But sometimes utility is premium.

Jon




At 10:06 AM 7/23/2010, you wrote:
Thank you, Jon. This is helpful but not exactly what I need. In fact, after
each line of text I have 122 pairs of numbers so it is _lines(123)
structure, and the number of structures is six. However, the real issue is
that those 122 pairs of numbers represent only two variables with 122
observations each. And this repeats six times. The final data structure
should be 6x2=12 columns (variables) with 122 observations each. Any idea
how can this be accomplished?
Andrzej




On 7/22/10 11:22 PM, "Jon Gettman" <jgettman@hughes.net> wrote:

> The test data file I set up literally uses "one line of text" as the
> string of text on the first,fifth, and ninth lines.  It gets
> truncated, and if the line of text is not needed in the dataset, this
> might work. Look at Example 7 in the manual on page 294.  Treat the
> structure as a 4 line data entry.  Then delete the first variable
> when you get the data loaded into Stata.
>
> dictionary using "C:\DATA\test.txt" {
> _lines(4)
> _line(1)
>                  str13   xxx             "onelineoftext"
> _line(2)
>                  int     a1              "a1"
>                  int     a2              "a2"
> _line(3
>                  int     b1              "b1"
>                  int     b2              "b2"
> _line(4)
>                  int     c1              "c1"
>                  int     c2              "c2"
> }
>
> .infile using "C:\Data\test.dct"
>
> xxx     a1      a2      b1      b2      c1      c2
> one     2       4       3       5       5      6
> one     1       3       2       7       7      6
> one     4       6       2       1       3       5
>
> I hope this helps.  Does this get you what you want?
> Jon
>
>
>
>
> At 11:38 AM 7/22/2010, you wrote:
>> I would appreciate help with -infile dictionary-.
>>
>> My data files have the following structure:
>>
>> One line of text
>> 2 4
>> 3 5
>> 5 6
>> One line of text
>> 1 3
>> 2 7
>> 7 6
>> One line of text
>> 4 6
>> 2 1
>> 3 5
>>
>> I want to read this file and create six numerical variables (three pairs)
>> corresponding to the three sections of numbers below each line of text.
>> Thank you.
>> Andrzej
>>
>>
>>
>>
>>
>> The information in this e-mail is intended only for the person to whom it is >> addressed. If you believe this e-mail was sent to you in error and the e-mail
>> contains patient information, please contact the Partners Compliance
>> HelpLine at
>> http://www.partners.org/complianceline . If the e-mail was sent to
>> you in error
>> but does not contain patient information, please contact the sender
>> and properly
>> dispose of the e-mail.
>>
>> *
>> *   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/

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