Announcement

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

  • Stata Programming help _ grouping do files by their size

    Dear all,

    I am struggling with one task. I have lets say around 100 do files of different sizes (some are small, less than 1 mb, some are up to 126mb). I need to split all the files whose weight is more than 3 mb into smaller files with weight up to 3 mb and then be able to put them back together

    It would be greatly appreciated if you could help me with some ideas


  • #2
    Welcome to Statalist.

    Are you sure you mean Stata do-files (suffix .do), which typically contain Stata commands, as opposed to Stata datasets (suffix .dat) which contain Stata data?

    Because a 126mb do-file, if in ASCII, would contain about 1.5 million 80-character lines of Stata code, which, unless is was generated by some other program rather than typed in by an army of research assistants, is difficult to imagine.

    Comment


    • #3
      Code:
      cd "path where your files are stored"
      local myfilelist: dir . files "*.dta"
      foreach file of local myfilelist {
        use `"`file'"'
        local outfile = subinstr(`"`file'"',".dta","",.)
        local N = _N
        local i = 1
        forvalues obs = 1(150)`N' {
            local lastobs= `obs'+149
            if `lastobs'>`N'{
              local lastobs= `N'
              }
            preserve
            keep in `obs'/`lastobs'
            save "`outfile'part`i'"
            restore
            local ++i
            }
      }

      Comment

      Working...
      X