Virata manual

Seeing the Python or the R

Print every command in another language as you run it.

What we have

  • pandas, R and the spelled-out Stata, any or all at once
  • from R mode as well: an R line shown as Stata and as pandas, with the missing-value rule converted, not just the syntax
  • 34 of the 46 R translations have been run in a real R and gave the same numbers
  • every block says whether it was checked, every time

Coming later

  • nothing from Python mode: a Python line is run as code, never parsed, so there is no tree to render — it says so when you switch
  • from R: a summary without na.rm = TRUE, a column named after a Stata storage type, and left_join are refused rather than mistranslated
  • R for graph, for the do-file programming commands, and for r()/e() — a command with no R form says so rather than guessing
  • an R prompt: R is shown, never typed
set show python on
set show r on
set show stata on

With this on, each result is followed by the same command written in another language. Any or all three can be on at once, and set show on its own says which are.

. set show r on
. summarize mpce if age >= 15

    ... the table ...

    --- the same in R ---
    library(dplyr)
    df %>% filter((stata_missing(age) >= 15)) %>% summarise(...)

What each one gives you

python — the pandas that actually ran. Not a translation written afterwards: the real thing. This is the honest answer to "what is this command doing?", and it is how you learn pandas while getting your work done.

stata — the line you typed, written out in full, with abbreviations spelled out and macros already substituted. Nothing is translated, because nothing needed to be. Useful for checking that su mp if cut'` meant what you intended.

r — the R you would write for the same job, in tidyverse style. R is *shown*, never typed: there is no R prompt here.

It works from R mode too, in reverse

Type dplyr and see the Stata or the pandas:

. set language r
> set show stata on
> df %>% filter(age > 60)

    --- the same in Stata ---
    keep if (age > 60) & !missing(age)

The !missing() is not decoration. R's filter() drops a row whose condition is missing; Stata's keep if keeps it. A translation that stopped at the syntax would give you Stata that runs and answers a different question.

It does not work in Python mode, and says so when you switch. A Stata command and an R line are each parsed into a tree, so either can be written out again. A Python line is run as code and never parsed, so there is no tree to render.

How far to trust the R

Each block ends with a line saying whether that command's R has been run in a real R and gave the same numbers. 34 of the 46 translations have been; the rest are documentation and say so. The comparison is a real test file that runs against a real R installation, not a claim.

stata_missing() appearing in the R is not decoration — see the missing-value rule. It is the most common way for a Stata result and an R result to disagree.

A command with no R form says so rather than guessing. graph, the do-file programming commands and the saved results r() and e() are the main gaps.