Announcement

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

  • File C:/Users/....xlsx could not be loaded

    I have a question regarding importing an Excel file in order to do HP-filtering. For some reason, I get error message: file C:/Users/....xlsx could not be loaded. Does anyone have an idea what is the reason for the error message? Thank you!

  • #2
    Please show us the command you tried.

    Comment


    • #3
      Please find it in the attachment.
      Attached Files

      Comment


      • #4
        There could be several issues here. If you are on windows and the excel file is open in excel, windows will maintain a "lock" on the file which may prevent Stata from opening the file. If the file is too large, it may also fail to load. Does the file open correctly in Excel? if not, the file itself may be corrupt.

        Loading a non-native binary can always be a little fraught, even with a well documented standard like .xlsx. If you're struggling, just use an interchange format instead. Save the excel file as a .csv, then load it with -insheet using-.

        By the way, I have literally never tried to load an excel file directly in Stata. I always use an interchange format like .csv to avoid all of the inevitable headaches that come with trying to load a non-native binary. I might use a tab-separated file if I think some columns will contain commas, but that's about it.

        (Yes, I know an excel file is essentially compressed xml, which is technically an interchange format. I would still rather use a simple plain-text format like .csv, especially if I know I just want a single table object.)

        Comment


        • #5
          The file opens in Excel without problems, and it was closed when I tried importing it to Stata. I also tried in CSV format, but I obtain the same error message. I'm sending the file in attachment. I will try with -insheet using-... do you have any examples of code? Thank you!

          Small correction: the .do file contains full link to the .xls file, but I censored part due to privacy concerns. It looks like "C:\Users\Name\....\Inflation.xlsx" rahter than just "Inflation.xlsx"
          In case I use just "Inflation.xlsx", and not full link, the error message changes to:

          file Inflation.xlsx not found
          Last edited by Svit Valencic; 03 Nov 2023, 12:37.

          Comment


          • #6
            No one is going to open your .xlsx attachment because it is a security risk. Generally, you don't want to attach things here. Just paste your commands into a post. In this case, if you attach the .csv I can see if it loads correctly on my end.

            Comment


            • #7
              I am attaching the .csv. Do you have any examples of the -insheet using- command?
              Attached Files

              Comment


              • #8
                Code:
                insheet using "Inflation.csv", clear
                loads the file in Stata 17, assuming the file is in your working directory. However, this does not look like a correctly formatted .csv file. These appear to be simicolon separated values rather than comma separated values.

                Use this instead:

                Code:
                import delimited "Inflation.csv", delimiters(";") clear
                Or even:

                Code:
                insheet using "Inflation.csv", delimiter(";") clear

                Comment


                • #9
                  Perfect, the last command works...btw. can you give me any advice on how to use one-sided HP filter? Thank you!

                  Comment

                  Working...
                  X