Announcement

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

  • #16
    Can you show the results of the following in your directory with the files:

    Code:
    filelist
    keep if regexm(filename, "\\$")
    dataex

    Comment


    • #17
      Originally posted by Justin Blasongame View Post
      Can you show the results of the following in your directory with the files:

      Code:
      filelist
      keep if regexm(filename, "\\$")
      dataex
      Code:
      . filelist
      Number of files found = 2
      
      . keep if regexm(filename, "\\$")
      (1 observation deleted)
      
      . dataex
      
      ----------------------- copy starting from the next line -----------------------
      
      
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str1 dirname str9 filename int fsize
      "." "$ROPE.csv" 4761
      end
      ------------------ copy up to and including the previous line ------------------ Listed 1 out of 1 observations
      It's working
      Last edited by Calvin Chen; 16 Dec 2020, 08:51.

      Comment


      • #18
        Can you tell me what happens when you change directory to the file with $ROPE.csv and run this:

        Code:
        filelist, pattern(*ROPE.csv)
        
        keep if regexm(filename, "\\$")
        assert `=_N' == 1
        replace filename = subinstr(filename, "$", "\\$", .)
        
        local toread = filename[1]
        import delimited using "`toread'", clear
        Last edited by Justin Niakamal; 16 Dec 2020, 09:01.

        Comment


        • #19
          Originally posted by Justin Blasongame View Post
          Can you tell me what happens when you change directory to the file with $ROPE.csv and run this:

          Code:
          filelist, pattern(*ROPE.csv)
          
          keep if regexm(filename, "\\$")
          assert `=_N' == 1
          replace filename = subinstr(filename, "$", "\\$", .)
          
          local toread = filename[1]
          import delimited using "`toread'", clear
          Code:
          . filelist, pattern(*ROPE.csv)
          Number of files found = 1
          
          . assert `r(N)' == 1
          
          . replace filename = subinstr(filename, "$", "\\$", .)
          variable filename was str9 now str10
          (1 real change made)
          
          .
          . local toread = filename[1]
          
          . import delimited using "`toread'", clear
          file \.csv not found
          I think we may meet the same problem here, still, the file is not found.

          Comment


          • #20
            Unfortunately, I can't reproduce what you're experiencing. The only thing I can suggest is updating your Stata (type update all in your Stata window) and running the code again.

            Code:
            filelist, pattern(*ROPE.csv)
            
            keep if regexm(filename, "\\$")
            assert `=_N' == 1
            replace filename = subinstr(filename, "$", "\\$", .)
            
            local toread = filename[1]
            import delimited using "`toread'", clear
            (12 vars, 74 obs)
            note:
            Code:
            . filelist, pattern(*ROPE.csv)
            Number of files found = 1
            
            . list
            
                 +-----------------------------+
                 | dirname   filename    fsize |
                 |-----------------------------|
              1. | .         $ROPE.csv   4,761 |
                 +-----------------------------+
            Last edited by Justin Niakamal; 16 Dec 2020, 09:13.

            Comment


            • #21
              Originally posted by Justin Blasongame View Post
              Unfortunately, I can't reproduce what you're experiencing. The only thing I can suggest is updating your Stata (type update all in your Stata window) and running the code again.

              Code:
              filelist, pattern(*ROPE.csv)
              
              keep if regexm(filename, "\\$")
              assert `=_N' == 1
              replace filename = subinstr(filename, "$", "\\$", .)
              
              local toread = filename[1]
              import delimited using "`toread'", clear
              (12 vars, 74 obs)
              note:
              Code:
              . filelist, pattern(*ROPE.csv)
              Number of files found = 1
              
              . list
              
              +-----------------------------+
              | dirname filename fsize |
              |-----------------------------|
              1. | . $ROPE.csv 4,761 |
              +-----------------------------+
              I have just tried to install and uninstall and also tried everthing in another Mac computer, all the attempts failed. I use Stata 16 IC, can I know what version do you use?

              Thank you very much for your help!

              Comment


              • #22

                I have just tried to install and uninstall and also tried everthing in another Mac computer, all the attempts failed. I use Stata 16 IC, can I know what version do you use?
                Here's my info

                Code:
                . about
                
                Stata/SE 16.1 for Mac (64-bit Intel)
                Revision 03 Dec 2020
                Copyright 1985-2019 StataCorp LLC

                Comment


                • #23
                  Originally posted by Justin Blasongame View Post

                  Here's my info

                  Code:
                  . about
                  
                  Stata/SE 16.1 for Mac (64-bit Intel)
                  Revision 03 Dec 2020
                  Copyright 1985-2019 StataCorp LLC
                  Thank you very much for your replies. I even tried to install a Stata/SE, but still, it didn't work. However, I have just now figured it out, we can use macval() to pass the text as it is. I was literally working on this question for a whole day!
                  in this case, the code is
                  Code:
                  local all_file: dir . files"*.csv"
                  foreach f of local all_file {
                      
                      insheet using "`macval(f)'", clear
                  }
                  I hope it would help people who need it in the future.

                  Have a nice day.

                  Comment


                  • #24
                    I didn't know about macval(), but that sure makes life easier! Thanks for sharing your solution.

                    Comment

                    Working...
                    X