Announcement

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

  • Error while using import command (quotations accepted by a Mac and not accepted by another Mac)

    Hi, I'm new in the Forum but I used Stata in the past while being a RA (and coming back again now).

    I wanted to use a global to import files faster. The code is the following (I'm using Mac):

    Code:
    clear all
    set more off
    
    global path "/Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia"
    import excel $path/RawData/CLASS.xlsx, firstrow clear
    It doesn't run on my Mac, but it does run on my colleague's Mac.
    What it does run in my Mac is using "" in the command import, as follows:

    Code:
    global path "/Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia"
    import excel "$path/RawData/CLASS.xlsx", firstrow clear
    Now, this inconsistency is important for us to solve, because my colleague's Mac does not run the code above (with quotation marks).
    We both use Stata 17.0

    Below, is the error I get from Stata:

    . clear all

    . set more off

    .
    . global path "/Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia"

    . import excel $path/RawData/CLASS.xlsx, firstrow clear
    using required
    r(100);

    end of do-file

    r(100);
    Thank you,

    Guido
    Attached Files

  • #2
    I suspect the full path is different. Different drive or some such.

    Comment


    • #3
      Code:
      global path "/Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia"
      import excel $path/RawData/CLASS.xlsx, firstrow clear
      fails because after Stata substitutes in the value of $path into your command, it tries to execute
      Code:
      import excel /Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia/RawData/CLASS.xlsx, firstrow clear
      and it sees two arguments "Users/guidodamonte/Dropbox/World" and "Bank/LTGM_WesternBalkans/LTGM_Serbia/RawData/CLASS.xlsx" and thinks that you are providing a list of variable names to assign to the imported columns and thus there needs to be a "using" following the last variable name before the filename.
      Code:
      global path "/Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia"
      import excel "$path/RawData/CLASS.xlsx", firstrow clear
      works because after Stata substitutes in the value of $path into your command, it tries to execute
      Code:
      import excel "/Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia/RawData/CLASS.xlsx", firstrow clear
      and it now does not treat the embedded space in "World Bank" as the end of the filename.

      Comment


      • #4
        Originally posted by William Lisowski View Post
        Code:
        global path "/Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia"
        import excel $path/RawData/CLASS.xlsx, firstrow clear
        fails because after Stata substitutes in the value of $path into your command, it tries to execute
        Code:
        import excel /Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia/RawData/CLASS.xlsx, firstrow clear
        and it sees two arguments "Users/guidodamonte/Dropbox/World" and "Bank/LTGM_WesternBalkans/LTGM_Serbia/RawData/CLASS.xlsx" and thinks that you are providing a list of variable names to assign to the imported columns and thus there needs to be a "using" following the last variable name before the filename.
        Code:
        global path "/Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia"
        import excel "$path/RawData/CLASS.xlsx", firstrow clear
        works because after Stata substitutes in the value of $path into your command, it tries to execute
        Code:
        import excel "/Users/guidodamonte/Dropbox/World Bank/LTGM_WesternBalkans/LTGM_Serbia/RawData/CLASS.xlsx", firstrow clear
        and it now does not treat the embedded space in "World Bank" as the end of the filename.
        Excellent, this was the solution!

        Thank you all for your help!

        Comment

        Working...
        X