Many thanks for all your attention. This was awesomely educational. I
had to delay the deletion of the file so that Stata would have it to
work on. In the end, I wound up with the following script:
fun! RunDoLines()
let selectedLines = getbufline('%', line("'<"), line("'>"))
if col("'>") < strlen(getline(line("'>")))
let selectedLines[-1] = strpart(selectedLines[-1], 0, col("'>"))
endif
if col("'<") != 1
let selectedLines[0] = strpart(selectedLines[0], col("'<")-1)
endif
let temp = tempname() . ".do"
call writefile(selectedLines, temp)
exec "!start C:\\Program Files\\Scripts\\rundo.exe " . temp
" Delete the temp file after Vim closes
au VimLeave * exe "!del -y" temp
endfun
DVM