Announcement

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

  • Stata won't open a dct file

    I use a Mac. I tried opening a dct file through the do. file provided. dct., dat. and do file all in same folder. Keep getting the r (601) ; error saying dct. not found.

  • #2
    I doubt anyone can help you until you show the exact code you tried using and the exact response you got from Stata. Do that by copying directly from the Results window or your log file and pasting here into the Forum editor, surrounding it by code delimiters. Do not modify it in any way: there are no "unimportant details" in code. If you are not familiar with code delimiters, please read FAQ #12.

    Comment


    • #3
      " /************************************************** ************************
      |
      | NATIONAL SURVEY OF FAMILY GROWTH (NSFG), 2013-2015
      |
      | STATA Female Data Setup File
      |
      |
      | Please edit this file as instructed below.
      | To execute, start Stata, change to the directory containing:
      | - this do file
      | - the ASCII data file
      | - the dictionary file
      |
      | Then execute the do file (e.g., do nsfg_female_setup.do)
      |
      ************************************************** ************************/


      set more off /* This prevents the Stata output viewer from pausing the
      process */

      /************************************************** **

      Section 1: File Specifications
      This section assigns local macros to the necessary files.
      Please edit:
      "data-filename" ==> The name of data file downloaded from NCHS
      "dictionary-filename" ==> The name of the dictionary file downloaded.
      "stata-datafile" ==> The name you wish to call your Stata data file.

      Note: We assume that the raw data, dictionary, and setup (this do file) all
      reside in the same directory (or folder). If that is not the case
      you will need to include paths as well as filenames in the macros.

      ************************************************** ******/

      local raw_data "2013_2015_FemRespData"
      local dict "2013FemPreg.dct"
      local outfile "2013-15_FemResponds"

      /************************************************** ******

      Section 2: Infile Command

      This section reads the raw data into Stata format. If Section 1 was defined
      properly, there should be no reason to modify this section. These macros
      should inflate automatically.

      ************************************************** ********/

      infile using `dict', using (`raw_data') clear


      /************************************************** *******



      this was the do file I used and renamed the file to the corresponding names.


      I'm a beginner at Stata and I usually had to work with dta files but these dct files somehow don't work with me.

      Comment


      • #4
        Well, the syntax in the do file looks OK. But it also looks like a huge trap for the unwary. The layout practically invites you to try to run Section 1 first and then run Section 2. And that won't work, because when you run a "chunk" of a do-file, any local macros defined in that chunk disappear at the end of that chunk. So if you define local macro dict in one chunk and then try to run -infile using `dict'...- in a separate chunk, `dict' will be undefined and Stata will be looking for a file named just .dct, and, of course, it will not exist. Similarly with local macro raw_data. So the first thing is to be sure to run this all in one fell swoop, not in chunks.

        If that is not the problem, we have to consider other possibilities as well. I have never known Stata to be wrong about a file not found. There are several possibilities here. One is that you have mistyped the name of one of the files. For example are you sure that the name of the raw data file actually begins with 2013_2015 and not 2013-2015? And if you are running this on a Mac, filenames are case sensitive, so an error in case will cause a file to fail to be found. Another possibility is that the files are not in the current working directory. Before running this code, run the command -dir- and see if these filenames show up.

        Comment


        • #5
          Thank you Clyde!

          Comment


          • #6
            Hi Kathleen,

            Were you able to get your problem resolved? I am facing the same issue with the following code.


            set mem 6m /* Allocating 6 megabyte(s) of RAM for Stata SE to read the
            data file into memory. */


            set more off /* This prevents the Stata output viewer from pausing the
            process */

            /************************************************** **

            Section 1: File Specifications
            This section assigns local macros to the necessary files.
            Please edit:
            "data-filename" ==> The name of data file downloaded from ICPSR
            "dictionary-filename" ==> The name of the dictionary file downloaded.
            "stata-datafile" ==> The name you wish to call your Stata data file.

            Note: We assume that the raw data, dictionary, and setup (this do file) all
            reside in the same directory (or folder). If that is not the case
            you will need to include paths as well as filenames in the macros.

            ************************************************** ******/

            local raw_data "C:\Users\ghosh\Dropbox\My PC (DESKTOP-A77V0A6)\Desktop\25861-0001-Data"
            local dict "C:\Users\ghosh\Dropbox\My PC (DESKTOP-A77V0A6)\Desktop\25861-0001-Setup"
            local outfile "C:\Users\ghosh\Dropbox\My PC (DESKTOP-A77V0A6)\Desktop\ICPSR1991"

            /************************************************** ******

            Section 2: Infile Command

            This section reads the raw data into Stata format. If Section 1 was defined
            properly, there should be no reason to modify this section. These macros
            should inflate automatically.

            ************************************************** ********/

            infile using `dict', using (`raw_data') clear

            Comment


            • #7
              Since you have appended your question to an existing thread, I will assume that you have actually read the thread up to that point. That would imply that you are actually not having the same problem, because the solution offered in #4 would resolve it. By having the same issue, then, I will take it that you really are running the code all at once, not in chunks, but you are nevertheless encountering a file not found error.

              There are two possibilities that leap to mind.
              1. The file that Stata is not finding actually does not exist in the specified directory. Perhaps its name is misspelled. Or perhaps it is in a different directory than you believe it is in. That is easy enough for you to double-check.
              2. If that is not the case, then it is likely arising from having surrounded the filenames in quotes when you defined the local macros. Stata strips initial and final quotes when they are specified in macro definitions. So the macro is not actually being defined the way you think it is. When that then gets substituted into the -infile- command and expanded, the absence of those quotes leaves you with an illegal file name, because it contains a blank space but is not surrounded by quotes. The solution is to use the quotes in the -infile- command, but not in the local macro definitions. So:
              Code:
              local raw_data C:\Users\ghosh\Dropbox\My PC (DESKTOP-A77V0A6)\Desktop\25861-0001-Data // N.B. No quotes
              local dict C:\Users\ghosh\Dropbox\My PC (DESKTOP-A77V0A6)\Desktop\25861-0001-Setup // N.B. No quotes
              
              infile using "`dict'", using ("`raw_data'") clear
              If that does not resolve your problem, re-run your code adding
              Code:
              set tracedepth 1
              set trace on
              immediately before the -infile- command and try again. That way you will see exactly what Stata sees in the local macros, and you will probably be able to make repairs accordingly.

              As an aside, there is no need for the -set mem- command unless you are running a very old version of Stata. All recent versions do memory allocation automatically and dynamically. While you can use -set mem- to override Stata's way of doing it, that usually makes things worse, not better.


              Comment

              Working...
              X