Announcement

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

  • Stata skips some line of commands in the do-file

    Hello.

    I have a long do-file. When I select all the commands in do-file and execute them, Stata skips some of the commands. But, does not give any error message or I cannot know if (and which) line of commands it has skipped. I only know that some of them were not executed when I want to do further analysis. But, there is no issue when I run the commands line by line.

    For example

    use "$data", clear

    keep ParticipantID BaseT_* Received T3_Year_of_Received Year_of_Assessment

    gen wave=1

    save "BaseT.dta", replace

    use "$data", clear

    keep ParticipantID Sixmfu_* Sixmonths_* Sixmontht_* Year_of_Assessment sixmontht_* sixmonths_* Received T3_Year_of_Received OffWorkDM_6mths_Days_1

    gen wave=2

    save "6month.dta", replace

    use "$data", clear

    keep ParticipantID ___12montht_* Twelvemfu_*

    gen wave=3

    save "12month.dta", replace

    append using "6month.dta"

    append using "BaseT.dta"

    append using "24month.dta"

    replace wave=4 if wave==.

    save "mindfourwaves_long.dta", replace



    Then when I tab ‘wave’ I find

    tab wave, m
    wave Freq. Percent Cum.
    1 1,340 26.5 26.5
    2 1,340 26.5 53.01
    3 1,340 26.5 79.51
    . 1,036 20.49 100
    Total 5,056 100
    This happens for other commands too.

    Does anyone has any idea what the issue is?

    Thanks a lot.

    Ama

  • #2
    Please give your code in the
    Code:
    
    
    delimiters so we can read this easier. Also, what are you expecting your code to do here? What is the outcome you seek? As it stands, I'm unclear how Stata is skipping lines in a do file.

    Comment


    • #3
      This is what your code looks like in a more readable format.
      Code:
      use "$data", clear
      keep ParticipantID BaseT_* Received T3_Year_of_Received Year_of_Assessment
      gen wave=1 
      save "BaseT.dta", replace
      
      use "$data", clear
      keep ParticipantID Sixmfu_* Sixmonths_* Sixmontht_* Year_of_Assessment sixmontht_* sixmonths_* Received T3_Year_of_Received OffWorkDM_6mths_Days_1
      gen wave=2
      save "6month.dta", replace
      
      use "$data", clear
      keep ParticipantID ___12montht_* Twelvemfu_*
      gen wave=3
      save "12month.dta", replace
      
      append using "6month.dta"
      append using "BaseT.dta"
      append using "24month.dta"
      replace wave=4 if wave==.
      save "mindfourwaves_long.dta", replace
      This would seem to lead to no values of wave being the Stata missing value . but in your tabulation we see
      Code:
      . tab wave, missing
      
             wave |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                1 |      1,340       26.50       26.50
                2 |      1,340       26.50       53.01
                3 |      1,340       26.50       79.51
                . |      1,036       20.49      100.00
      ------------+-----------------------------------
            Total |      5,056      100.00
      I have highlighted in red the command that you think was not run, because your subseqeunt tab shows observations where wave is missing rather than 4. The idea is that the 24month dataset did not have the variable wave in it, so it is missing in those observations, and you wanted to replace those missing values with 4.

      I've reached the limits of what I can say about this problem. It would be interesting to see what the output in the Stata Results window was after the replace command - it should tell you how many values were replaced.

      If this is a reproducible problem - that is, if every time you run the code above the tabulations shows that the missing values were not replaced - then you should run the entire block of code at once and copy the output from Stata's Results window and paste it into a reply using code delimiters [CODE] and [/CODE] to surround the output so it is clearly rendered.

      One other possibility is that you start by saying you have a long do-file, but what you show us is not particularly long. Perhaps what you have presented isn't really what you ran, but a simplification that you think will help other members solve your problem. In that case, the problem is likely that your simplification doesn't include the actual cause of the problem. It is never a good idea to present anything other than exactly what you ran, exactly as you ran it.

      Comment


      • #4
        Thanks Jared and William for your reply.

        William, you have correctly explained the issue I have. My do-file is about 2000 lines, and what Stata skips is not the same line every time I run the do-file. For example, the first time I run the do-file, it may skip line 10 and 600; second time it may be line 200 and 1000. What I have copied before is just the illustration of the problem.







        Comment

        Working...
        X