Announcement

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

  • Problems loading data

    Hello,

    I have downloaded three files from a governmental website: a do-File, a dct-File and a txt-File. The instructions from their website states that I should open the .do file with Wordpad and insert paths for the following three lines:
    local raw_data "C:\....."
    local dict: "C:\..."
    local outfile "C:\...\
    I inserted the correct paths where the files where located and saved the .do file as a new file and then started Stata 14. I wanted to load the .do file but it would not do anything. Then on another forum someone wrote that one needs to add single quotes, i.e. `"C:\...."'. I did this and additionaly, I added double quotes to `dict' in the -infile- command, i.e. I have changed it to: infile using "`dict'", using (`raw_data') clear. Once again I loaded the .do file, and now it seemed to load a lot of variables, but at one point the following error message showed up: option using() incorrectly specified
    r(198);
    end of do-file.

    Can you help me out on this?
    Thank you very much
    A.C






  • #2
    Please show us the content of the dofile, using the code tag.
    Jorge Eduardo Pérez Pérez
    www.jorgeperezperez.com

    Comment


    • #3
      In the meantime I managed to load the do file, but unfortunately there are no numbers showing up. During the loading of the data the following errors pop up:
      'ENH' cannot be read as a number for SC9E[9738]
      'YDR' cannot be read as a number for SC9F[9738]
      'AMI' cannot be read as a number for SC9G[9738]
      'NE"' cannot be read as a number for SC9H[9738]
      'D' cannot be read as a number for SC9_02[9738]
      .....this happens for all the variables.
      As to the contents of the dofile, I will post only part of the do-File. as it is very big.


      /************************************************** ************************
      |
      | STATA SETUP FILE FOR ICPSR 20240
      | COLLABORATIVE PSYCHIATRIC EPIDEMIOLOGY SURVEYS (CPES),
      | 2001-2003 [UNITED STATES]
      | (DATASET 0002: NATIONAL COMORBIDITY SURVEY REPLICATION
      | (NCS-R), 2001-2003)
      |
      |
      | 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 20240-0002-statasetup.do)
      |
      ************************************************** ************************/

      set mem 100m /* Allocating 100 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:\Documents and Settings\Administrator\Desktop\NCS\ICPSR_20240\DS0 002\20240-0002-Setup.do"'
      local dict `"C:\Documents and Settings\Administrator\Desktop\NCS\ICPSR_20240\DS0 002\20240-0002-Setup.dct"'
      local outfile `"C:\Documents and Settings\Administrator\Desktop\NCS\ICPSR_20240\DS0 002\icpsr2167.dta"'

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

      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


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

      Section 3: Value Label Definitions
      This section defines labels for the individual values of each variable.
      We suggest that users do not modify this section.

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


      label data "Collaborative Psychiatric Epidemiology Surveys (CPES), 2001-2003 [United States], Dataset 0002"

      #delimit ;
      label define CHILDREN -9 "REFUSED" .r "REFUSED" -8 "DONT KNOW" .d "DONT KNOW" 4 "4 OR MORE" ;
      label define ADOL -9 "REFUSED" .r "REFUSED" -8 "DONT KNOW" .d "DONT KNOW" 3 "3 OR MORE" ;
      label define ADULT -9 "REFUSED" .r "REFUSED" -8 "DONT KNOW" .d "DONT KNOW" 5 "5 OR MORE" ;
      label define HHSIZE -9 "REFUSED" .r "REFUSED" -8 "DONT KNOW" .d "DONT KNOW" 7 "7 OR MORE" ;
      label define SC7 -9 "REFUSED" .r "REFUSED" -8 "DONT KNOW" .d "DONT KNOW" 1 "CURRENT" 2 "EX-SMOKER"
      3 "NEVER" 4 "(IF VOL) ONLY SMOKED A FEW TIMES" ;
      ..................................
      ..................................
      /************************************************** *************************

      Section 4: Extended Missing Values

      This section will recode numeric values (i.e., -8) with extended missing
      values (i.e., '.d'). By default the code in this section is commented out.
      Users wishing to apply the extended missing values should remove the comment
      at the beginning and end of this section. Note that Stata allows you to
      specify up to 27 unique extended missing value codes.

      ************************************************** **************/
      /*
      foreach v of varlist _all {
      capture replace `v' = .n if `v' == -7
      capture replace `v' = .d if `v' == -8
      capture replace `v' = .r if `v' == -9
      }
      */

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

      Section 5: Save Outfile

      This section saves out a Stata system format file. There is no reason to
      modify it if the macros in Section 1 were specified correctly.

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

      save "`outfile'", replace




      Comment


      • #4
        The Do-file you presented specifies for the macro raw_data the name of the downloaded Stata Do-file.

        The instructions request that raw_data be the name of file containing the data - in your case, the file with the txt suffix.

        Comment


        • #5
          Thanks Mr. Lisowski, that worked!

          Comment

          Working...
          X