Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Importing fixed width data using infix - dictionary invalid

    Hello,

    I am importing fixed with data from a .txt file. Here is my code:

    Code:
    cd "...\1973-09-to-2014-06\non-dod\status"
    
    infix id 1-9 name 10-32 filedate 33-40 agency 41-44 ///
    station 45-53 age 54-59 educationlevel 60-61 ///
    payplan 62-63 grade 64-65 los 66-71 occupation 72-75 ///
    occ_cat 76 pay 77-82 supervisory_status 83 appointment 84-85 ///
    schedule 86 nsftp ind 87 using Status_Non_DoD_1973_09.txt
    Stata returns the error that the dictionary is invalid. I have verified that the .txt file is in the working directory, so I'm unsure why I get this error.

    Thank you.
    Last edited by Greg Saldutte; 23 May 2019, 08:56.

  • #2
    Hi Greg,

    It would have been helpful if you could have posted some example data of what you wanted to import, as you are asked to do so in the FAQ.

    Here is a toy example. Suppose I have a file, test.txt with the following contents:

    Code:
    123456789 bob 37 71.5
    Then I run the following code to import the file.

    Code:
    infix id 1-9 str name 11-13 age 15-16 height 18-21 using test.txt
    My code is correctly imported, as shown by -list-

    Code:
                 id   name   age   height  
      1.   1.23e+08    bob    37     5.25
    As I read your command, there are (at least) two errors, the second of which is causing Stata to complain.

    1) name is invariably going to be a string, so you will need to tell Stata this fact by specifying -str name 10-32-. This is demonstrated in the syntax specification for the -infix- command and throughout the help file. The same will apply to any other string variables. Note, if you omit -str- then Stata will silently impute a missing value and will warn you, but continue with importing the data.

    2) the column index(es) are missing for the variable nsftp in -schedule 86 nsftp ind 87-. This is what Stata is complaining about.

    Comment


    • #3
      Thank you Leonardo. The problem was solved when I specified string.

      Comment

      Working...
      X