Announcement

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

  • Working directory with spaces

    I am using the cd command (cd "C:\Users\Arbnor Gashi\Desktop\Stata new 2018\Lessons and practice") to define the working directory, but since there is a space between my first and last name, the Stata doesn't recognizes it. Could you please tell me how to solve this problem?

    Thanks in advance,
    Arbnor Gashi

  • #2
    The " " should be sufficient to cope with that space (and several others). I never willingly put spaces in file or directory names, partly because I use Stata and save more that way than I lose.

    Comment


    • #3
      Since Nick doesn't use spaces in his file paths, let me provide an example from my filesystem that shows a cd command like yours that works. If your problems continue, copy the command that fails and its error message from the Stata Results window and paste it into a code block in the Forum editor using code delimiters [CODE] and [/CODE].

      My example:
      Code:
      . cd "/Users/lisowskiw/Research/Social Capital (SWB)/180728 190314"
      /Users/lisowskiw/Research/Social Capital (SWB)/180728 190314
      
      . pwd
      /Users/lisowskiw/Research/Social Capital (SWB)/180728 190314

      Comment


      • #4
        Dear Lisowski, the main problem is with the spacing that exists in between my first and last name. I think it should be a command to tell Stata that there is space in there, since the point that Nick Cox mention doesn't make any sense.
        Below I attached a photo with the warning that I got from Stata.
        Click image for larger version

Name:	pr1.PNG
Views:	1
Size:	27.7 KB
ID:	1493515

        Comment


        • #5
          Code:
          use "$MY_IN\new26co.dta", clear

          Comment


          • #6
            The problem seems more to be about correct usage of global macros.

            Code:
            use "$MY_IN\new26co.dta", clear
            Best
            Daniel

            Comment


            • #7
              Nope Daniel. I have used the same before but since dell changed my account name then folder name was changed to name and last name and didn't work anymore.
              I have an example which worked well and finished a paper without having problems.

              global MY_DO "C:\Users\arbno\Desktop\TwinCrises\do"
              global MY_IN "C:\Users\arbno\Desktop\TwinCrises\in"
              global MY_LOG "C:\Users\arbno\Desktop\TwinCrises\log"
              global MY_OUT "C:\Users\arbno\Desktop\TwinCrises\out"
              global MY_TEMP "C:\Users\arbno\Desktop\TwinCrises\temp"


              log using $MY_LOG/TWINCRISESnew.log, append

              use $MY_IN\TWINCRISESnew.dta, clear


              This worked perfectly. My problem happend first when the name was changed. So it might be better to contact guys from dell in order to learn how to change users name in folder.



              Comment


              • #8
                It is really not that complicated.

                When you define

                Code:
                global MY_IN "C:\Users\arbno\Desktop\TwinCrises\in"
                and then code

                Code:
                use $MY_IN\TWINCRISESnew.dta, clear
                Stata sees

                Code:
                use C:\Users\arbno\Desktop\TwinCrises\in\TWINCRISESnew.dta, clear
                which, of course, works. Note that you may add double quotes (although they are not needed here). Thus,

                Code:
                use "$MY_IN\TWINCRISESnew.dta", clear
                would work the same way. Stata sees

                Code:
                use "C:\Users\arbno\Desktop\TwinCrises\in\TWINCRISESnew.dta", clear

                If you now insert spaces

                Code:
                global MY_IN "C:\Users\Arbnor Gashi\Desktop\TwinCrises\in"
                and call

                Code:
                use $MY_IN\TWINCRISESnew.dta, clear
                Stata sees

                Code:
                use C:\Users\Arbnor Gashi\Desktop\TwinCrises\in\TWINCRISESnew.dta, clear
                and complains, because you cannot have spaces in file/path names; unless, of course, you add double quotes, which you do not do here. Changing the above to

                Code:
                use "$MY_IN\TWINCRISESnew.dta", clear
                will, again, work perfectly despite spaces. It works because Stata sees

                Code:
                use "C:\Users\Arbnor Gashi\Desktop\TwinCrises\in\TWINCRISESnew.dta", clear
                and is happy to load the file.


                The simple bottom line is this: either do not use spaces in file/path names or use double quotes whenever you refer to file/path names.

                Best
                Daniel
                Last edited by daniel klein; 16 Apr 2019, 06:35. Reason: added summary line of advice

                Comment

                Working...
                X