编辑: 252276522 | 2017-10-07 |
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. dyndoc ― Convert dynamic Markdown document to an HTML ?le
3 ~~~~ assert mpg >
0 &
mpg <
100 assert mpg >
0 &
mpg <
100 ~~~~ 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: ~~~~ summarize weight ~~~~ We want to use the minimum and maximum values of **weight** in a sentence. Instead of copying and pasting the numbers from the **summarize** output, we can use the **dd_display** Stata dynamic tag with the **r(min)** and **r(max)** stored results: ~~~~ The variable weight has minimum value and has maximum value . ~~~~ This produces the following in the target HTML file: ~~~~ >
The variable weight has minimum value and has maximum value . ~~~~ The **dd_display** dynamic tag uses Stata'
s **display** command to evaluate expressions. It can be used as a calculator. For example, if we want to include the $$range = max - min$$ in a sentence, instead of calculating the number and then copying and pasting it, we can use ~~~~ The variable weight has range . ~~~~ which produces the following in the target HTML file: ~~~~ >
The variable weight has range . ~~~~ Now, we want to graph **mpg** and **weight** using a scatterplot. We use the **dd_do** tag with the **nooutput** attribute to generate the scatterplot first. The **nooutput** attribute leaves the command in the output only,
4 dyndoc ― Convert dynamic Markdown document to an HTML ?le ~~~~ scatter mpg weight, mcolor(blue%50) ~~~~ which generates a scatterplot of **mpg** and **weight** with 50% opacity color markers. ~~~~ scatter mpg weight, mcolor(blue%50) ~~~~ Now, we want to export the graph to a file and include an image link to the file. ~~~~ ~~~~ This produces a graph of
400 pixels high. end dyndoc ex.txt Technical note We use four tildes in a row, ~~~~, in our source ?le around parts of the document that we want to appear in plain text, such as Stata commands and output. Without the ~~~~, Stata'
s output would be interpreted as HTML in the ?nal document and would not look as it should. You will notice that we used the dynamic tag to include ........