Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st:How to input a portion of a file


From   "Friedrich Huebler" <[email protected]>
To   [email protected]
Subject   Re: st:How to input a portion of a file
Date   Thu, 21 Feb 2008 14:30:23 -0500

Joseph,

Before you delete the header area, you can store a single line of data
in a macro for subsequent processing.

. insheet using test.txt, nonames delimiter(" ")
. local header = v1[4] + " " + v2[4] + " " + v3[4]
. di "`header'"
mpg trunk turn

Friedrich

On Thu, Feb 21, 2008 at 11:23 AM, Joseph Wagner
<[email protected]> wrote:
> As Friedrich pointed out, Stata does import the columnar data quite well
>  and deleting the first lines of the 'header' region will work - to a
>  point.  I do have a single line of data that I need from the header
>  area.  I would be happy to send the ascii text file as well as the excel
>  spreadsheet that has the needed variables highlighted if anyone is
>  interested in getting a better look.
>
>  [snip]
>
>  >> Assume we have a file "test.txt" that contains the following text
>  >> (without the Start and End lines). We are only interested in the
>  >> numbers.
>  >>
>  >> === Start of file ===
>  >> I am not clear how that this will help, as the header text and
>  >> the remainder of the file will give -insheet- quite different
>  >> ideas about what variables there are.
>  >> mpg trunk turn
>  >> 22 11 40
>  >> 17 11 40
>  >> 22 12 35
>  >> 20 16 40
>  >> === End of file ===
>  >>
>  >> Let's import the data with -insheet-.
>  >>
>  >> . insheet using test.txt, nonames delimiter(" ")
>  >> (14 vars, 8 obs)
>  >> . drop if _n < 5
>  >> (4 observations deleted)
>  >> . drop v4 - v14
>  >> . list
>  >>
>  >>     +--------------+
>  >>     | v1   v2   v3 |
>  >>     |--------------|
>  >>  1. | 22   11   40 |
>  >>  2. | 17   11   40 |
>  >>  3. | 22   12   35 |
>  >>  4. | 20   16   40 |
>  >>     +--------------+
>  >>
>  >> Friedrich
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index