-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Repeated use of a template
- Loading branch information
Showing
13 changed files
with
181 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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">> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters