Announcement

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

  • #delimit ;

    I am working with code that someone else created. They appear to have used a semicolon demiter-- #delimit ; is the first line of the file. The code broke after about a day, and I was trying to troubleshoot by rerunning specific sections, but I could not get the code to run. I even copied over a specific section into a new .do file and made sure that the first line was #delimit ; . The code still did not run. HOWEVER, when I removed the first line (#delimit ;) and removed all the semicolons from the ends of each statement, it ran fine. Can anyone explain what's going on here?

  • #2
    Please use dataex to provide a sample to increase your chances of getting an answer. Without an example it is hard to say...

    Comment


    • #3
      Your question really isn't clear without more detail, or at a minimum it is too difficult to guess at a good answer from what you have shared. Please help us help you. Show your code. Show us what Stata told you. Tell us what precisely is wrong. The Statalist FAQ provides advice on effectively posing your questions, posting data, and sharing Stata output.

      In presenting your code please copy commands and paste them into your Statalist post using code delimiters [CODE] and [/CODE] to surround the code, as described in the FAQ.

      Comment


      • #4
        My apologies. Below I've copied the relevant pieces of the header of the original data file and the section that the code broke at. When I try running this on its own, it does not run; however, if I remove the first line (#delimit and remove all the semicolons from the end of the statements, it runs fine.

        Code:
         
        #delimit ;
        clear all;
        set more off;
        
        set mem 800m;
        set seed 792655464;
        
        global statelist        AL AK AZ CA CO DE FL GA /*ID*/ IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT WA WV WI WY /*AR CT HI VA VT*/;    
        global non_merged       AL AK /*AZ CA CO DE FL GA ID IL*/ IN /*IA*/ KS /*KY LA ME*/ MD /*MA*/ MI MN MS /*MO*/ MT /*NE NV*/ NH NJ NM /*NY NC*/ ND OH OK /*OR PA*/ RI /*SC SD*/ TN TX /*UT WA*/ WV WI /*WY AR CT HI VA VT*/;  
        
        foreach prefix in $statelist {;
            foreach non_merge in $non_merged {;
                if "`prefix'" == "`non_merge'" {;
                    use "S:\Projects\Project\Data\Files_Final\States\\file_`prefix'_AB.dta",clear;
                    foreach var in County Term_Adjustment_Flag Term_Adjustment_Rule Term_Adjustment_Type {;
                        rename `var' Prison_`var';
                    };
                    save "S:\Projects\Project\Data\Files_Final\States\\file_`prefix'_AB2.dta", replace;
                };
            };
        };

        Comment


        • #5
          please write

          help delimit

          then enter
          the help file is pretty clear I think on what is happening. it has an example as help files usually do...

          Comment


          • #6
            When you run exactly the code you show in post #4, does it fail, and if so, what does Stata tell you?

            My belief is that you have a mistake in the code before where the program fails, that you are not showing us, and the mistake is not enough to cause the program to fail immediately, but instead it continues until something breaks later.

            When using semicolon delimiters, one common way for this to happen is to accidentally omit a semicolon, so two commands are run together as one. Here's what I mean - this do-file runs with no error message, but will later break because $blist is empty and $alist includes entries "global" and "blist".

            Code:
            . #delimit ;
            delimiter now ;
            . global alist AK AL
            > global blist AL;
            
            . foreach a in $alist {;
              2.         display "`a'";
              3. };
            AK
            AL
            global
            blist
            AL
            
            . foreach b in $blist{;
              2.         display "`b'";
              3. };
            
            .

            Comment

            Working...
            X