Announcement

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

  • display filename while appending files in stata

    This is the overview of my project:
    Main folder < subfolders < subfolders < excel files
    Note: Over 500 xls files and a lot of Excel files have multiple tabs/sheets so want to capture that data also.
    1. Convert from xls to dta
    2. In my final appended dataset I want to keep track of the excel file name that each observation came from. So somehow create a new variable FILENAME. As each file is converted, input the name of the excel file in the variable FILENAME for each observation in that file.
    3. Append all dta files (all excel files have identical variables)
    Code:
    xls2dta , clear generate(filename) recursive allsheets: append using ., importopts(allstring)
    Problem: Stata runs the code for quite some time but then always gets stuck at this file. Is there a way we can know what file this is so I can go back to it and identify the source of why Stata doesn't append beyond this point.
    Attached Files

  • #2
    I am not sure why you do not continue your previous thread. Anyway, there is an undocumented verbose option that provides intermediate output. Type

    Code:
    xls2dta , clear generate(filename) recursive allsheets verbose: append using ., importopts(allstring)
    If that does not help, you either need to

    Code:
    set trace on
    for which the output will be massive and hard to follow or set up the importing loop yourself.


    Edit:

    By the way, xls2dta is (probably) from SSC, as you are asked to explain. Also, because you are appending all sheets, you probably want generate(filename sheetname) as an option.
    Last edited by daniel klein; 20 Jan 2023, 12:16.

    Comment

    Working...
    X