Skip to content

Commit

Permalink
Update Quarto inline code docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hugetim committed Oct 25, 2024
1 parent a3ba998 commit 740dd9a
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions nbs/user_guide.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -491,19 +491,32 @@
"\n",
"### Inline calculations\n",
"\n",
"To embed calculations [inline](https://quarto.org/docs/computations/execution-options.html#inline-code) in Markdown output, the workaround is to use Stata's `display` command to output Markdown, combined with the `*| output: asis` Quarto cell option. For example:\n",
"With nbstata v0.8+, you can use the standard Quarto syntax for [inline code](https://quarto.org/docs/computations/inline-code.html), specifying the Stata expression as '[%*fmt*] *exp*', just as you would for a Stata [`display` command](https://www.stata.com/help.cgi?display). For example:\n",
"\n",
"```stata\n",
"*| output: asis\n",
"*| echo : false\n",
"qui:sysuse auto, clear\n",
"qui:regress price mpg\n",
"display \"Based on the model, when a car is *more* fuel efficient, the cost\n",
"*decreases* by \\$\" %5.2f `=abs(_b[mpg])' \".\"\n",
"````qmd\n",
"```{stata}\n",
"*| include: False\n",
"sysuse auto, clear\n",
"regress price mpg\n",
"```\n",
"would ultimately result in output like this:\n",
"An *increase* of one mpg is associated with a *decrease* in price of \\$`{stata} %5.2f abs(_b[mpg])`.\n",
"````\n",
"would result in output like this:\n",
"\n",
"> An *increase* of one mpg is associated with a *decrease* in price of \\$238.89.\n",
"\n",
"> Based on the model, when a car is *more* fuel efficient, the cost *decreases* by \\$238.89.\n"
"::: {.callout-warning}\n",
"Stata locals cannot be referenced within inline code like \\`x' because the tick (or \"left single quote,\" as Stata's manual calls it) conflicts with Quarto's inline code syntax. You can instead use globals or scalars to pass things to inline code.\n",
"\n",
"For example, this gives the same output as above (whereas defining 'mpg_coef' as a local would not work):\n",
"````qmd\n",
"```{stata}\n",
"*| include: False\n",
"scalar mpg_coef = string(abs(_b[mpg]), \"%5.2f\")\n",
"```\n",
"An *increase* of one mpg is associated with a *decrease* in price of \\$`{stata} mpg_coef`.\n",
"````\n",
":::"
]
}
],
Expand Down

0 comments on commit 740dd9a

Please sign in to comment.