Announcement

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

  • Using Import delimited with variable names in another .txt file

    Dear all,
    I need to import panel data to Stata. I have two files; one file in .DAT format containing the observations or data, and another in .txt containing the variable name and specifications. I made it previously, but I don't find the do file where I introduced the instruction, and now I am struggling to figure out how to incorporate the variables' names and labels into the data file.

    I have transformed data from .DAT to .dta using "import delimited":

    Code:
    import delimited "file1", encoding(UTF-8)
    The resulting .dta file has this aspect:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int v1 byte(v2 v3 v4 v5 v6 v7) int v8 byte(v9 v10 v11)
     1 1 1 2 2 2 2 2003 2 4 2
     2 . . . . . .    . . . .
     3 2 2 2 2 2 2 1948 4 4 2
     4 . . . . . .    . . . .
     5 . . . . . .    . . . .
     6 2 2 2 2 2 2 1973 1 1 1
     7 . . . . . .    . . . .
     8 . . . . . .    . . . .
     9 2 2 2 . . .    . 1 1 1
    10 . . . . . .    . . . .
    11 . . . . . .    . . . .
    12 . . . . . .    . . . .
    13 . . . . . .    . . . .
    14 2 2 2 2 2 2 1957 4 4 4
    15 . . . . . .    . . . .
    16 . . . . . .    . . . .
    17 . . . . . .    . . . .
    18 . . . . . .    . . . .
    19 2 2 2 2 2 2 1973 1 1 4
    20 2 2 2 1 1 1 1969 4 4 4
    end

    The .txt file where variables are described has this aspect:

    Code:
       1  ORDINAL                          1 -    10
       2  Activ    
           Year ....... 2007         12 -    17
           Year ....... 2008         19 -    24
           Year ....... 2009         26 -    31
           Year ....... 2010         33 -    38
        3 InternRD
           Year ....... 2007         61 -    66
           Year ....... 2008         68 -    73
           Year ....... 2009         75 -    80
           Year ....... 2010         82 -    87
    My question:
    How can I include the variable names and relationships in the .dta file?

    Thank you very much for your help in advance.
    Best regards,
    Last edited by Alexandra Maso; 13 Sep 2022, 06:43.

  • #2
    Your .txt file looks like a dictionary file that is used to interpret fixed width data, which is stored in your .dat file. Except I don't think the data dictionary is in a format that Stata directly understands. You may need to modify that file. See
    Code:
    help infix
    Last edited by Hemanshu Kumar; 13 Sep 2022, 10:16.

    Comment


    • #3
      Thank you for your kind reply. After trying with infix and infile commands, the storage type of the variables was float, so I proceeded to use:

      Code:
      import delimited
      It worked with the latter command. Thank you very much for your suggestions.

      Best regards,

      Comment

      Working...
      X