Skip to content

Commit

Permalink
updates;
Browse files Browse the repository at this point in the history
Repeated use of a template
  • Loading branch information
Hemken committed Oct 17, 2019
1 parent 80f89fb commit d770e18
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Markdown/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ table, th, td {
border: 1px solid black;
}
blockquote {
border-left: solid blue;
outline-style: solid;
padding-left: 10px;
}
</style>
Expand Down
12 changes: 12 additions & 0 deletions Usage/Dataset reports.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
clear
sysuse auto

levelsof rep78, local(rep78levels)

foreach level of local rep78levels {
preserve
keep if rep78==`level'
stmd "repeated datasets.stmd" `level', saving("rep78_data_`level'.html") ///
replace embedimage
restore
}
10 changes: 10 additions & 0 deletions Usage/Frame reports.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
clear frames
sysuse auto

levelsof rep78, local(rep78levels)

foreach level of local rep78levels {
frame put if rep78==`level', into(rep78_`level')
stmd "repeated frames.stmd" `level', saving("rep78_`level'.html") ///
replace embedimage
}
97 changes: 97 additions & 0 deletions Usage/Repeated Reports.stmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<<dd_include: "topmatter.txt">>

# Repeat a Report with Different Data

- [Using Subsets of a Single Data Set](#using-subsets-of-a-single-data-set)
- [Using Frames (Stata 16)](#using-frames-stata-16)
- [Using Separate Data Sets](#using-separate-data-sets)

Each of these methods makes use of *passing arguments* in the
`stmd` command. Repetition is accomplished by putting `stmd`
inside a loop.

## Using Subsets of a Single Data Set

Suppose this is the content of our Stata Markdown, in a file
name "repeated subsets.stmd".


````
<<dd_include: "repeated subsets.stmd">>
````

We can process this for each subset of the data with the
following commands (in a separate do file)


````
<<dd_include: "Subset reports.do">>

````

The last of the five reports is

----
<<dd_include: "rep78 eq 5.html">>

----

## Using Frames (Stata 16)

We can modify out report Markdown and the set up for our loop over
the `stmd` command to make use of Stata's `frames`. The key element
is once again passing an argument with the `stmd` command.

Suppose this is the content of our Stata Markdown, in a file
now named "repeated frames.stmd".

````
<<dd_include: "repeated frames.stmd">>
````

We can process this for each subset of the data with the
following commands (in a separate do file)

````
<<dd_include: "Frame reports.do>>"

````

The third of these five reports is

----

<<dd_include: "rep78_3.html">>

---

## Using Separate Data Sets

Actually, we can repeat this report just by swapping out data sets -
no argument passing is required for that. But we will make use of
a passed argument to write headings for our report sections.

Suppose this is the content of our Stata Markdown, in a file
now named "repeated datasets.stmd".

````
<<dd_include: "repeated datasets.stmd">>

````

We can process this for each subset of the data with the
following commands (in a separate do file)

````
<<dd_include: "Dataset reports.do">>

````

The first of these five reports is

---

<<dd_include: "rep78_data_1.html">>

---
<<dd_include: "bottommatter.txt">>
9 changes: 9 additions & 0 deletions Usage/Subset reports.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
clear
sysuse auto

levelsof rep78, local(rep78levels)

foreach level of local rep78levels {
stmd "repeated subsets.stmd" `level', saving("rep78 eq `level'.html") ///
replace embedimage
}
2 changes: 1 addition & 1 deletion Usage/graphing.stmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

Begin by drawing a graph. If you are using standard Markdown and creating
an HTML file, this will produce a separate PNG graphics file in the same
folder as your HTML file (? even if you specify a different output path?).
folder as your HTML file.

This text in your Markdown
````
Expand Down
9 changes: 9 additions & 0 deletions Usage/repeated datasets.stmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#### Descriptive Statistics where rep78 == <<dd_display: `1' >>
```stata, nocommands
summarize mpg weight
```

#### Regressing mpg on weight (rep78==<<dd_display: `1' >>)
```stata, nocommands
twoway (scatter mpg weight) (lfit mpg weight)
```
9 changes: 9 additions & 0 deletions Usage/repeated frames.stmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#### Descriptive Statistics where rep78 == <<dd_display: `1' >>
```stata, nocommands
frame rep78_`1': summarize mpg weight
```

#### Regressing mpg on weight (rep78==<<dd_display: `1' >>)
```stata, nocommands
frame rep78_`1': twoway (scatter mpg weight) (lfit mpg weight)
```
9 changes: 9 additions & 0 deletions Usage/repeated subsets.stmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#### Descriptive Statistics where rep78 == <<dd_display: `1' >>
```stata, nocommands
summarize mpg weight if rep78==`1'
```

#### Regressing mpg on weight (rep78==<<dd_display: `1' >>)
```stata, nocommands
twoway (scatter mpg weight) (lfit mpg weight) if rep78==`1'
```
19 changes: 19 additions & 0 deletions Usage/usage docs.do
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cd "z:/Stata/stmd/usage"

capture erase Graph.svg

stmd stmdusage.stmd, replace
file_equal stmdusage.html using stmdusage-bm.html, display
assert r(differences)==0
Expand All @@ -12,3 +13,21 @@ assert r(differences)==0
stmd stmdcodeoptions.stmd, replace
file_equal stmdcodeoptions.html using stmdcodeoptions-bm.html, display
assert r(differences)==0

stmd graphing.stmd, replace

do "Subset reports.do"
do "Frame reports.do"
do "Dataset reports.do"
stmd "Repeated Reports.stmd", replace

forvalues i=1/15 {
erase "Graph`i'.png"
}
forvalues i=1/5 {
erase "rep78 eq `i'.html"
erase "rep78_`i'.html"
erase "rep78_data_`i'.html"
}

copy "Repeated Reports.html" "Z:/PUBLIC_web/Stataworkshops/stmd/Usage/Repeated Reports.html", replace
2 changes: 1 addition & 1 deletion Utils/ftype_stmd_16.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
assoc .stmd = Stata16Markdown
assoc .dyn = Stata16Markdown
ftype Stata16Markdowntata C:\Program Files\Stata16\StataSE-64.exe" -doedit %1
ftype Stata16Markdown = "C:\Program Files\Stata16\StataSE-64.exe" -doedit %1
Binary file modified stmd.stpr
Binary file not shown.
7 changes: 4 additions & 3 deletions stmd2dyn.ado
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*! version 1.7.1
*! version 1.7.2
*! Doug Hemken
*! 2 Oct 2019
*! 17 Oct 2019

// ISSUES
// ======
Expand All @@ -11,13 +11,14 @@
// capture program drop stmd2dyn
// capture mata: mata clear
program define stmd2dyn, rclass
syntax anything(name=infile), [ ///
syntax anything(everything), [ ///
SAVing(string) replace ///
noGRAPHlinks ///
nomsg ///
]

version 15
gettoken infile opargs : anything

local infile = ustrtrim(usubinstr(`"`infile'"', `"""', "", .))
*display `"infile is `infile'"'
Expand Down

0 comments on commit d770e18

Please sign in to comment.