Announcement

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

  • "Mandatory Element Missing" While importing data from Excel into Stata

    Hi I am getting an error "Mandatory Element Missing" While importing data from Excel into Stata 12. Is it due to any problem with variable's name given to my data in Excel file or ???. Thanks

  • #2
    I doubt anyone will be able to respond to this question--you don't give us much to go on. Show us the exact command you gave, along with Stata's exact response (copy-pasted from the Results window: don't retype by hand) in a code block (see FAQ for how to set up a code block). A view of some of the data in the Excel file might help as well.

    Comment


    • #3
      Hi Clyde. Thank you for your kind reply. Actually I just imported an excel file with (.xlsx) extension through File - Import Option without any other command. But it gives an error on window That "Mandatory Element Missing". Please see the photo I attached here. Thanks

      Comment


      • #4
        Ali, it appears from your screenshot that the worksheet was not selected. This may be a reason. In Stata 13 the worksheet is selected automatically, but probably not in 12. Check if you can select it in the dialog. If not, then the file is not readable. Also try if you can open it with Excel itself, and if yes, re-save in a different format.

        There were a few bugs with importing Excel data fixed in the time between v12 and v13 of Stata. I'd recommend you upgrade.

        Early mentioning of your problem go all the way to 2011: http://www.stata.com/statalist/archi.../msg00278.html
        So try to google the error message for solutions.

        Best, Sergiy Radyakin

        Comment


        • #5
          Hi Sergiy. Thanks for your reply. I changed file format from .xlsx to .csv, it worked well. I don't know the reason why my stata is not importing an excel file, but anyway it imported csv file. Thanks a lot Clyde and Sergiy.

          Comment


          • #6
            Ali, I use Stata SE 12 and had the same problem when running a script that I had used on a different computer presumably with a different version of stata. While I can not say exactly why this worked, I saved the file from an .xlsx to an .xls extension and the code accordingly and it worked out.

            I wanted to mention this (3 years later) in case you want to keep the excel formatting. For example, my excel file had variables in a date format. Saving it as a csv changed that date to a string, which jammed up my code. Saving as an .xls file kept the original formatting.

            Comment


            • #7
              Any such discussions are rather fruitless without the problematic file itself. Too many unknowns. Even with descriptions.
              Does "I changed file format from .xlsx to .csv" mean:
              • "I renamed the file?" or
              • "I used Stat/Transfer to convert the file?" or
              • "I used authoring tool X to write the same data in a different format"?
              I believe that there are too many possibilities of what can happen.

              I barely can remember any of the problems related to importing Excel files to Stata from year 2015, but Stata 14 and 15 seem to work very well now, that the initial problems have been ironed out, so if this is an option, consider an upgrade (and it seems that regardless which earlier version you have 12 or 13 or 14) it will still save you quite a bit of cost of transiting to the current version.

              Can Ali and Chris perhaps give practical examples of where the data needs to be moved from Excel to Stata? Excel is commonly used as a reporting tool, where various summaries and results of analysis will be written to, but (at least in my field) not so commonly used as a source of information for importing to Stata (for various reasons, mostly due to lack of structure enforcement there).

              Best, Sergiy

              Comment


              • #8
                Excel is commonly used as a reporting tool, where various summaries and results of analysis will be written to, but (at least in my field) not so commonly used as a source of information for importing to Stata (for various reasons, mostly due to lack of structure enforcement there).
                I think this is very discipline, and maybe even institution-specific. In my work, the vast majority of data, unfortunately, comes to me as Excel files. It seems to be a species of data-related software that pretty much everyone among my colleagues has, so it tends to get used for sending data around even though it is really rather poorly suited for the purpose.

                Comment

                Working...
                X