<> capture graph describe Graph tempname gdate local `gdate' = "`r(command_date)' `r(command_time)'" <> <> <> Using Stata dynamic tags in a text file with the dyndoc command =============================================================== Let us consider an example where we study the **mpg** and **weight** variables in **auto.dta**. In our examples below, we will first write the commands so that they will be displayed in our target HTML file. Then, we will write the commands so that Stata will process the Stata dynamic tags, displaying the results of the Stata commands in the target HTML file. We first use the **sysuse** command to load the dataset and then describe the data using the **describe** command. ~~~~ <> ```{stata} <> sysuse auto, clear describe <> ``` <> capture graph describe Graph local checkdate = "`r(command_date)' `r(command_time)'" <> <> <> <> <> local `gdate' = "`r(command_date)' `r(command_time)'" <> <> ~~~~ This produces the following Stata results: ~~~~{stata} <> sysuse auto, clear describe <> ~~~~ <> capture graph describe Graph local checkdate = "`r(command_date)' `r(command_time)'" <> <> <> <> <> local `gdate' = "`r(command_date)' `r(command_time)'" <> Now, we want to check if **mpg** is always greater than 0 and less than 100. We use the **assert** command to perform the check. In this case, we do not want to include any output in the target HTML file, so we use the **quietly** attribute to modify the behavior of the **dd_do** Stata dynamic tag. ~~~~ <> ~~~{stata} <> assert mpg > 0 & mpg < 100 <> ~~~ <> capture graph describe Graph local checkdate = "`r(command_date)' `r(command_time)'" <> <> <> <> <> local `gdate' = "`r(command_date)' `r(command_time)'" <> <> ~~~~ ~~~~{stata} <> assert mpg > 0 & mpg < 100 <> ~~~~ <> capture graph describe Graph local checkdate = "`r(command_date)' `r(command_time)'" <> <> <> <> <> local `gdate' = "`r(command_date)' `r(command_time)'" <> If the data do not satisfy the conditions, **dyndoc** will fail with an error message, which will occur if we run the same **assert** command in a do-file. Next, we want to summarize the **weight** variable: ~~~~ <> <> summarize weight <> <> ~~~~ This produces the following in the target HTML file: ~~~~{stata} <> summarize weight <> ~~~~ <> capture graph describe Graph local checkdate = "`r(command_date)' `r(command_time)'" <> <> <> <> <> local `gdate' = "`r(command_date)' `r(command_time)'" <>