Announcement

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

  • How many lines of code can stata run at once?

    Hi folks,

    I am very new to stata so my question might sound naive. I now have a file with around 800 lines of code, they are mostly data cleaning and table-making. My dataset has about 60k observations, not small but not super huge. The problem is, whenever I try to run more than 200/300 lines of codes simultaneously, stata will tell me the code has been run, but I will not see any results. I am suppose to export an Excel file with more than 10 tables, but sometimes I only see 1 table within that file. Is there anyway I can run the entire file at once without those problems?

    I am using STATA 18 Basic Edition, my device is M1 Macbook Air(Should be powerful enough for my dataset).

    Will it be different if I use a Windows device or upgrade to STATA18 SE?

  • #2
    EDIT: This is wrong. See #4

    I don't believe there is a hard limit to the number of lines of code Stata can run given sufficient time. Keep in mind, the computer doesn't run the lines "simultaneously", it runs each line one at a time in order. There is nothing that I'm aware of that should stop you from being able to automate this process for an arbitrarily large number of lines of code. I've just used excel to create a basic script that repeats the display command 800 times and displays the number associated with the current line. I won't paste it into a post (as is generally preferred) because it's a very long script file, but you should see it attached. The script completes execution without error on my end.

    Something else must be stopping execution before the script completes. Usually that would be accompanied by an error code, but it's difficult to say without knowing more details. Are you certain no error is printed to the console?
    Attached Files
    Last edited by Daniel Schaefer; 12 Jul 2023, 20:50.

    Comment


    • #3
      Also, you are new to Stata and you've already written an 800 line do file? Or did you inherit the do file from someone else? Setting aside the fact that an 800 line do file should be fine from Stata's point of view, I would still break that up into multiple do files, where each do file does a specific task. For example, you might have one data cleaning script, then write your clean data to a new data file at the end. Then consume the clean dataset in a new do file for analysis. 800 lines of code sounds difficult to maintain. My do files are rarely more than 200 to 300 lines, and many are only 50-100 lines. From a purely organizational point of view, it's usually a good idea to break your code into small, modular chunks. The machine doesn't care, but it makes it easier for humans like you and me.

      Comment


      • #4
        Actually, looks like there are some well documented limits on do file sizes:

        https://www.stata.com/products/detailed-size-limits/

        Check your do file to make sure it has fewer than 135,600 bytes (135.6 KB) and 3500 lines. If it does, the solution is, again, to break the file into smaller chunks. If not, there may be some other issue. Sorry for spamming your thread!

        Comment


        • #5
          Originally posted by Daniel Schaefer View Post
          Actually, looks like there are some well documented limits on do file sizes:

          https://www.stata.com/products/detailed-size-limits/

          Check your do file to make sure it has fewer than 135,600 bytes (135.6 KB) and 3500 lines. If it does, the solution is, again, to break the file into smaller chunks. If not, there may be some other issue. Sorry for spamming your thread!
          That's fine, thanks a lot. It's my own do-file, but most of my codes are repetitive, as I am making tables for several different subgroups of my dataset. And 50% of codes are about making tables prettier. I wonder if that has something to do with me exporting dozens of tables in my code? I don't see any error sign displayed on the window.

          Comment


          • #6
            As a bit of an aside, this is possibly a sign that you should be making more use of the foreach or forvalues loop:

            It's my own do-file, but most of my codes are repetitive
            I notice you say in #1 that sometimes you only see a single table in the output file. Do you have any sense of why you only see a single table sometimes? For example, does this happen only when you try to run the entire do file? In cases where you only see a single table in the output file, which table is it? The first? The last? Some table between the first and the last? Is it always the same table, or does it change sometimes?

            I have another question: Stata will typically print the command it is running to the console. When you run the do file and allow the program to exit on its own, do you see the last command in your do file also in the console?

            Comment


            • #7
              Originally posted by Daniel Schaefer View Post
              Actually, looks like there are some well documented limits on do file sizes:
              [...]
              I believe this statement applies to programs in a strict sense, i.e., the (exectuted) lines between program and end.

              I can run a 4,000 lines do-files on Stata 17 without a problem.

              Comment

              Working...
              X