Announcement

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

  • Infix problem

    My old Stata commands for reading in a DAT file with infix aren't working. I'm using a dictionary because it's a multi-record data set.

    I've entered three versions of the same command intended to read the dictionary file. They differ only in the use of quotation marks:

    infix using "C:\WP.DOC\Jews\Yankelovich1981\Yank8225.dict

    infix using "C:\WP.DOC\Jews\Yankelovich1981\Yank8225.dict"

    infix using C:\WP.DOC\Jews\Yankelovich1981\Yank8225.dict

    Each command returns the same error (601) which is not helpful:

    file C:\WP.DOC\Jews\Yankelovich1981\Yank8225.dict not found

    The dictionary file is a text file created in Notepad (attached). There is nothing wrong with the directory. The following command (with an intentional error) located the data file in the same directory:

    . infix using "C:\WP.DOC\Jews\Yankelovich1981\YANK8225.DAT
    000114233121213122121212 22 24411514777113137411133312333 1111211122222222221
    file does not contain dictionary
    r(613);


    I'm using Stata IC 14.2 with Windows 7.

    Any suggestions? Thanks.
    Attached Files

  • #2
    Making sure both files are in the same working directory, you may wish to try something like:

    Code:
    . infix using filename.dct , using(filename.txt)
    To end, I guess the extension for dictionary is .dct
    Last edited by Marcos Almeida; 10 Mar 2017, 15:42.
    Best regards,

    Marcos

    Comment


    • #3
      Thanks for the suggestion. I tried it with several variations but still got error 601 about file not found.

      I keep thinking there must be some piddling little format error with the call for the dictionary but I can't see it. I hope somebody can help.

      Thanks again.

      Comment


      • #4
        The file you attach has a different name with an extra extension .txt at the end. Stata won't ignore that difference.

        Comment


        • #5
          Originally posted by Nick Cox View Post
          The file you attach has a different name with an extra extension .txt at the end. Stata won't ignore that difference.
          Thanks for catching that. I know that Wordpad saves it as a text file but I didn't realize it appended an extension to that effect. But there doesn't seem to be any way around that. If I drop the ".dict" extension and just use the txt extension, Stata still rejects the file. It gives me the same 601 error. Is there a workaround? I appreciate your help. Ken

          Comment


          • #6
            Ken:

            Wordpad is not a program I use on purpose but my understanding is that if you save a file as a text document it wants to slap on a .txt extension, almost regardless of whether you have given a name ending in a plausible extension. If it's like other such programs, you have to insist on exactly which name you want by enclosing that name in " ".

            You started well in #1 by showing us commands and error messages but you need to keep that up!

            I would first change directory

            Code:
            cd  "C:\WP.DOC\Jews\Yankelovich1981"
            just to make things simpler. Now show us the exact infix command you are trying together with the results of

            Code:
            dir Yank8225*
            assuming that you think the file you want to use at least starts with that.
            Last edited by Nick Cox; 11 Mar 2017, 10:23.

            Comment


            • #7
              Yes, I believe that you're writing the file extension manually and using .dict instead of .dct.

              Comment


              • #8
                Stata now has me totally confused. Thanks for all the help but still no execution.

                I fixed the dictionary file so it no longer has the .txt extension and has the proper .dct extension. I also renamed it. It seems to find the dictionary file because it reads the first line (the second command) but now it give me a different error message.

                . infix using C:\WP.DOC\Jews\Yankelovich1981\Yank8225test.dct , using(C:\WP.DOC\Jews\Yankelovich1981\YANK8225.DAT)
                infix using "C:\WP.DOC\Jews\Yankelovich1981\YANK8225.DAT
                file does not contain dictionary

                The second infix command above (infix using "C:\WP.DOC\Jews\Yankelovich1981\YANK8225.DAT) is the first line in the dictionary file. Thinking that was unnecessary, I edited the dictionary file to remove that line so it just begins with the { . This generated this error message:

                . infix using C:\WP.DOC\Jews\Yankelovich1981\Yank8225test2.dct , using(C:\WP.DOC\Jews\Yankelovich1981\YANK8225.DAT)

                {
                file does not contain dictionary

                Unfortunately, this board now won't let me upload either the dict or dat files.

                So once I again I have to impose on you for advice on what to try next.

                Ken

                Comment


                • #9
                  Sorry but I didn't catch the lack of a space between the "using" and "(C:" in my command. Fixing it didn't help:

                  . infix using "C:\WP.DOC\Jews\Yankelovich1981\Yank8225test.d ct , using (C:\WP.DOC\Jews\Yankelovich1981\YANK8225.DAT)
                  file C:\WP.DOC\Jews\Yankelovich1981\Yank8225test.dct , using (C:\WP.DOC\Jews\Yankelovich1981\YANK8225.DAT) not found

                  I'm not sure if it there's something wrong with the .DAT file or the problem is something else altogether.

                  Thanks again.



                  Comment


                  • #10
                    There must be no space between the "using" option and the parenthesis, hence you won't need to fix it.

                    You may wish to take a look at the exemples from the Stata Manual,

                    To end, as already mentioned in #2, I strongly recommend to have all data sets in the same directory. What is more, it gets much easier if you make sure to have selected the "right" working directory. Since you will need less typing, the probability of mistyping decreases.
                    Last edited by Marcos Almeida; 11 Mar 2017, 14:11.
                    Best regards,

                    Marcos

                    Comment


                    • #11
                      Look at the error message again.

                      You don't close the " ": there is only one quotation mark ".

                      As a result Stata thinks you are referring to a file with the name

                      Code:
                      C:\WP.DOC\Jews\Yankelovich1981\Yank8225test.dct , using (C:\WP.DOC\Jews\Yankelovich1981\YANK8225.DAT
                      That is, the message has the form

                      file <filename> not found

                      where in this case <filename> is the entirety of the string above; and naturally that string is not the name of the file you want to specify.

                      I gave you advice in #6 to change directory. If you had followed that advice, you might not have made this error. Marcos I think is making the same point.

                      Comment


                      • #12
                        Thanks again, guys. It's probably relevant to mention that I have vision problems and this sometimes makes it a challenge to catch typing errors.

                        So here's what I ran with your suggestions and the Stata response.

                        cd "C:\WP.DOC\Jews\Yankelovich1981"
                        C:\WP.DOC\Jews\Yankelovich1981


                        . infix using Yank8225test2.dct , using(YANK8225.DAT)

                        {
                        file does not contain dictionary
                        r(613);

                        The curly bracket is now the first line in the dictionary file,

                        I've tried to upload the dictionary file but I get a message saying the file is invalid and won't upload. When I saved the DAT file, I used the procedure you suggested by enclosing the file name in double quotations and it saves it as an unhandled extension. That's what the help page I used told me would happen. Since it won't upload, I'm going to paste in the text of the .dct file:


                        {

                        6 lines

                        1:
                        ID 1-5
                        q3a1 16
                        q3a2 17
                        q3a3 18
                        q3a4 19
                        q3a5 20
                        q3a6 21
                        q3a7 22
                        q5-1 27
                        q5-2 28
                        q5-3 29
                        q6-3 32
                        q6-4 33
                        q6-5 34
                        q6-7 36
                        q6-8 37
                        q6-9 38
                        q6-10 39
                        q6-11 40


                        4:

                        q27 40
                        q28a 41
                        q28b 42
                        q28c 43
                        q29 44
                        age 45
                        marital 46
                        raised 47
                        yrslived 48
                        reduc 49
                        paeduc 50
                        maeduc 51
                        roccstat 53
                        hhoccstat 54
                        relig 55
                        attend 63
                        party 64
                        ideo 65
                        presvote80 57

                        5:

                        faminc 36
                        classid 53
                        chclassid 54
                        sex 62
                        race 63
                        intrelig 66

                        6:

                        region 38
                        metsize 39
                        areatype 40
                        areasize 41
                        sample 42



                        }


                        I can't begin to thank you enough for your help.

                        Ken

                        Comment


                        • #13
                          I wonder whether changing the extension from .DAT to .txt would tackle the issue. Then, you may use the command shared in #2. Be sure this .DAT file is really a text file, because .DAT file can store other things.
                          Best regards,

                          Marcos

                          Comment


                          • #14
                            The dictionary file doesn't start as dictionary files should. help infix does explain.

                            Beyond that, did you know that you can change the font size within Stata's windows?

                            Under Windows, for example, right-clicking within Results or Command windows leads to a way to change it. (Perhaps other windows too; I have not tried them all.)

                            Comment


                            • #15
                              The penny finally dropped. I took another look at the commands I used to create similar .dta files with infix five years ago and realized that I needed to begin the dictionary file with the "dictionary file using" command. That worked and it read my data. It really helped to change the directory with cd. I haven't used that command since the days of fortran and didn't realize it existed in Stata despite having read a couple of user guides when I transitioned from SPSS.

                              I did encounter another small problem. One of the variables has two non-numeric characters (a dash and the &amp. It used zero to indicate category #10. I defined this as a string variable in the dictionary and then destrung it and gave it a unique name with this command:

                              destring areasize, generate(areasize3) ignore("&;-")
                              areasize: characters &amp;amp; - removed; areasize3 generated as byte
                              (204 missing values generated)

                              I was then able to recode the value of zero to ten:

                              recode areasize3 (0 = 10)

                              However, there's a problem I can't seem to figure out from the documentation. As it happens, the two values indicated by non-numeric characters and the value represented by zero represent the same category for purposes of my analysis. I could simply redefine the missing values as 10 and those 204 cases would become part of the same category as those cases previously assigned 0. But suppose I wanted to retain the cases with values originally represented as - and & but now as numeric 11 and 12? As I understood the distinction between encode and destring in one of your recent posts, encode would not be a helpful option here. Would the replace option overcome the problem? I promise I read the destring documentation carefully, knowing I was inquiring of its creator!

                              This isn't a deal killer for me because I don't absolutely have to use this variable but would like to. Thanks.

                              Ken


                              .

                              Comment

                              Working...
                              X