Bookmark and Share

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


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

Re: st: Using infile with varying lines() per observation


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Using infile with varying lines() per observation
Date   Thu, 25 Jul 2013 20:28:15 -0400

Kevin, considering your described setup the following should work:

type http://radyakin.org/statalist/2013072501/testdata.txt
do http://radyakin.org/statalist/2013072501/readflex.do

Here is the output:

id col1 col2 col3 col4
1 A     B    C   7
        B
2 A     B    C   1
3 A     B    C   90
        B
        B


    id   col1   col2   col3   col4
     1      A     BB      C      7
     2      A      B      C      1
     3      A    BBB      C     90


It's up to you to make sure that 244 chars is enough for the whole BBB
value and that the numbers are completely located in the first line of
each subject. Id is assumed to be a string.

Hope this helps, Sergiy Radyakin









On Thu, Jul 25, 2013 at 7:05 PM, Sergiy Radyakin <[email protected]> wrote:
> just to confirm, is it fixed? or is it space-separated? or tab separated?
> is only the second column affected or other columns may have the same problem?
> Sergiy
>
> On Thu, Jul 25, 2013 at 5:35 PM, Kevin McConeghy
> <[email protected]> wrote:
>> Hello users,
>>
>> It may be that STATA can't do this, I couldn't seem to find any
>> reference to it online or the listserve. I am trying to import data
>> that is in fixed format text files like so:
>>
>> id col1 col2 col3
>> 1  A     B    C
>>            B
>>
>> 2 A      B    C
>>
>> 3 A      B    C
>>            B
>>            B
>>
>> The key is Col2 which contains essentially free text I was hoping to
>> import as a string. The problem is that the text varies in length per
>> observation and therefore each observation occupies varying numbers of
>> lines.
>>
>> Infile allows you specify more than one line per obs through the
>> lines() option, but doesn't seem to let you vary this number. Is there
>> a user-written program for this? or some other way to address the
>> problem?
>>
>> I think SAS can do this, but I prefer staying in STATA if I can.
>>
>> Kevin
>> --
>> Kevin McConeghy, PharmD, BCPS
>> 833 S Wood St, Chicago, IL 60612
>> College of Pharmacy, Dept. of Pharmacy Practice
>> University of Illinois at Chicago
>> (312)-413-1422, [email protected]
>> *
>> *   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/
*
*   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/


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