Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Over the course of recent weeks, I experimented with Stata's new dyndoc command and started to like it a lot for generating a "static" html-file. However, what I really would like to do, is to create an "html-application" where the user can enter a few parameters and, on that basis, let some Stata code run in the background. Is there something like R's markdown with shiny runtime available for Stata?

    Comment


    • #17
      Daniel: Not that I am aware of. You can email StataCorp for "Numerics by Stata" if you need customized support. https://www.stata.com/products/numerics-by-stata/

      Robert Grant is working on D3 interactive graphics in a web browser, stata2d3: https://github.com/robertgrant/stata2d3

      Comment


      • #18
        German Rodriguez

        Let med be very clear: I admire the work you do, and I think we should be very thankful. I could mention a few other differences between what is available in Stata and in other software for literate/dynamic programming (using RStudio, which you mention), but then Stata has a major strength in its programming language. So yes, I join German in recommending Stata users to try markstat.

        I don't know about other users, but what I would like to have, is a long file (similar to Notebook in RStudio) that includes some text and easily distinguishable code that is used for the project, with only a few parts of the code printed in the compiled document. It seems this becomes rather messy in Stata's own editor and so far I have not been able to develop something easy to use with Sublime Editor (but this might be possible in Sublime Editor with a markstat theme better adopted to dynamic programming).

        Comment


        • #19
          Thanks Guest, I appreciate your comments. I think we can make progress if we focus on specific areas that can be improved in Stata, and you mention a couple.

          R Notebooks. There are at least two aspects to R Notebooks as described here. One is the ability "to test and iterate when writing code". You can do this with Stata code in markstat when using the Stata code editor, just highlight the code and run it. R Studio does the same, but splices the output just below the chunk. Rendering the Markdown narrative is a separate step in both environments, but see the last point.

          Another is the ability to render the document as an HTML notebook with output: html_notebook, which lets you show and hide the code and download the source script. This seems quite doable, and I will certainly look into adding a notebook output option to markstat in a future update. In the meantime, you can hide code by using a quiet chunk option (/, equivalent to echo=FALSE). I know, it's not the same.

          Sublime. Max Masnick has used markstat with Sublime, see https://maxmasnick.com/2017/09/22/markstat/. I have tried Visual Studio Code, a multiplatform extensible editor that understands Markdown natively and can render it as you type. But we would need an extension to run Stata code from it. Because Markdown is so simple and renders so quickly, I just use the Stata code editor.
          Last edited by sladmin; 11 Dec 2017, 09:53. Reason: anonymize poster

          Comment


          • #20
            German Rodriguez I appreciate what you have done with markstat. It provides a nice structure and syntax parallel to RMarkdown, which makes it easier to move from one to the other. I haven't quite figured out what all I can do with markstat yet, though. Does it support yaml headers? For my class slides, e.g., I typically include in my yaml header a chunk like:

            Code:
            output:
              beamer_presentation:
                theme: "metropolis"
                colortheme: "dove"
                fonttheme: "structurebold"
                fig_caption: false
            But when I try that in a .stmd file, I get the error:

            Code:
            . //_1
            . theme: "metropolis"
            command theme is unrecognized
            r(199);
            Is there a way to include options in the header, or do you need to do it in the command line, as in:

            Code:
            markstat using deck, beamer(metropolis)
            If the latter, how does one specify colortheme and the other options?

            Comment


            • #21
              I'm really enjoying trying out - markstat -. Another set of options that haven't been mentioned in this thread yet are Ben Jann's excellent weaving programs - texdoc - and - webdoc - programs from SSC.


              German Rodriguez I'm using some of the example scripts from http://data.princeton.edu/stata/markdown/simpleScript and I'm having some issues (though I probably should just start another thread for this).

              For example,

              1. the docx version isnt being created from commands like:

              Code:
                 markstat using test.stmd ,   docx
              Code:
                  markstat using test. stmd ,  strict   docx
              For me, it gives the error "file /Users/ebooth/Library/Application Support/Stata/ado/plus/m/markstat.docx not found "

              2. I'm also having trouble understanding how to insert macros and stored results. Using the examples on the markstat site: for code like
              Code:
              `s %3.1f _b[foreign]`
              the output in html/pdf is just : s %3.1f _b[foreign] not the values it's storing. When I insert local macros like
              Code:
                local j = 15
              the results for
              Code:
                `s `j'`   or `j'
              in the output pdf/html file is just `s `j'` or `j' .

              3. Finally, when I try the -tabout- code in the examples on your site it says there are some invalid options. I think this is because you are using the new beta -tabout- from Ian Watson's site not tabout 2.0.7 Ian Watson 5jan2015 from SSC.

              Thanks for any advice you might be able to give on these errors and thanks for providing this incredibly helpful weaving program (and all the awesome/useful Stata examples on your site - the HLM examples you provide are a favorite of mine).



              Here's the sandbox of code that I'm using to produce markstat documents:



              Code:
              ```{s}
              title(Toy example of markstat)
              ```
              
              Let us read the fuel efficiency data that is shipped with Stata
              
                  sysuse auto, clear
              
              To study how fuel efficiency depends on weight it is useful to
              transform the dependent variable from "miles per gallon" to
              "gallons per 100 miles"
              
                  gen gphm = 100/mpg
              
              We then obtain a more linear relationship
              
                  twoway scatter gphm weight || lfit gphm weight ///
                      , ytitle(Gallons per Mile) legend(off)
                  graph export auto.png, width(500) replace
              
              ![Fuel Efficiency](/users/ebooth/desktop/auto.png)
              
              
              ```{s}
              regress price mpg t*
              foreach j in turn trunk {
                  su `j', d
                  }
                  
                  
              ```s/
                   sum weight
                  local meanwt = r(mean)
                   sum length
                  local meanlen = r(mean)
                  local obs = r(N)
                   tabout2 rep78 foreign using table34.html, replace ///
                      style(htm) font(italic) c(mean weight) f(0c) sum ///
                      twidth(9) h1(Car type (mean weight in lbs.)) h3(nil) ///
                      title(Table 34: Short report example) fn(auto.dta)
              ```
              
              The title of my short report
              ----------------------------
              
              This is an excerpt of the report to focus on the dynamic parts.
              And now we have an important result: __`s %3.2f `meanwt'`__ is
              the average weight of all vehicles. And a second important 
              result: __`s %3.2f `meanlen'`__ is the average length.
              
              And now we have the first table.
              
               <center>
              
              include table34.html
              
              </center>
               
               
                   
                  
              ```s/
                   quietly gen gphm = 100/mpg
                  eststo clear
                  quietly eststo: regress gphm foreign
                  quietly eststo: regress gphm foreign weight
                  esttab
              ```
              
               We see that on average foreign cars are more economical, but
              if we adjust for weight they are less fuel efficient, using
              `s %3.1f _b[foreign]` gallons *more* instead of one gallon
              *less* per 100 miles. 
              
                  ```s/
                  local j = 15 
                  ```
               take a look    `s `j'`   or `j' 
              
              
                  gen gphm = 100/mpg
              
              We then obtain a more linear relationship
              
              ![Fuel Efficiency](auto.png){width="4.5in"}
              
              which was plotted using the commands
              
                  twoway scatter gphm weight || lfit gphm weight ///
                      , ytitle(Gallons per Mile) legend(off)
                  graph export auto.png, width(500) replace
              
              The regression equation estimated by OLS is
              
                  regress gphm weight    
                  
              Thus, a car that weights 1,000 lbs more than another requires on
              average an extra `s %5.1f 1000*_b[weight]` gallons to travel 100 
              miles.
              
                  
              That's all for now!
              Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

              Comment


              • #22
                Thanks Eric Lawrence. While I kept many parallels with R Markdown for precisely the reason you note, there are some differences. An important one is that markstat uses Stata options to specify the output format, whereas R Markdown uses YAML. I thought that would seem more natural to Stata users. So yes, you need to specify the output format in the command line, as your last code chunk shows.

                The error 199 occurred because markstat interprets text indented one tab or four spaces as a Stata command, unless you use the strict option. In this case it was tripped by the theme specification, and if you remove this bit of YAML all will be well. Alternatively, if you are using code fences, try

                Code:
                markstat using deck, strict beamer(metropolis)
                As for the last question, yes, you can specify a color and font theme. We use Pandoc under the hood, and the template for Beamer presentations has variables for colortheme and fonttheme. These can be set directly in YAML metadata (just not as part of R's beamer_presentation sequence). So your YAML block could look something like this:

                Code:
                ---
                title: your title
                author:  Eric Lawrence
                colortheme: "dove"
                fonttheme: "structurebold"
                ---
                You could even specify the theme here, and just say beamer in the command line. As for the figure caption, in markstat you use Markdown to include your figures and get a chance to specify a caption or leave it blank, so this option does not apply.

                I wonder if at this point it might not be better to start a new thread for markstat issues.


                Comment


                • #23
                  Hi eric_a_booth. Sorry I somehow overlooked your post when I was replying to the other Eric. Ben Jann made excellent contributions with -texdoc- and -webdoc- as noted in my SJ 17-3 paper, and of course that's were the -nodo- option came from. Regarding your questions (and yes, I think starting a new thread would be better)

                  1. Can you verify that -markstat.docx- is in fact in your ADO PLUS folder? Not sure why it is not found, as Stata seems to be looking in the right place.

                  2. The inline code looks fine to me, both the first example and the first version of the second; just tried them and they work, except `j' which by itself would do nothing.

                  3. This is the easiest one, the example using -tabout- is indeed based on version 3 of Ian Watson's command. Also, the .include command should start with a dot.

                  Your sandbox code seems to mix the simple and strict syntax. If this is all part of the same script or more likely several bits put together? The best way to provide a title is to put it in the first line starting with a % symbol. This should replace the first three lines. The next eleven then should run fine under the simple syntax. The next fenced block (with the regression and loop) is not closed, you need ``` after the loop. If you are trying examples on the website note that you can download the scripts from Stata, e.g. for the simple script

                  Code:
                  copy http://data.princeton.edu/stata/markdown/simpleScript.stmd simpleScript.stmd
                  markstat using simpleScript
                  should do the trick. You can then try making changes to that script. Hope this helps.

                  Comment


                  • #24
                    German Rodriguez - thanks for the helpful reply.

                    Here's what I found:

                    For #2: the issue was my improperly mixing the simple and strict syntax - good catch. I wanted to test out a lot of different features and pulled your examples together without regard for this difference. Thanks for the clarification the macro substitution is working now.

                    For #3, thanks for confirming, I've got various (hacked/manipulated) versions of -tabout- on my machine as I test components of the new beta and wanted to confirm that there wasnt something I was missing (or had broken) .
                    For #1: there is not a markstat.docx file in my ado plus folder.
                    I checked my ado plus paths and checked that the permissions were correct on the folder so that it's not being prevented from writing there.
                    I ran the exact code below on STata 15.1 MP Mac OSX 10.13.1:


                    Code:
                    copy http://data.princeton.edu/stata/markdown/fuel.stmd fuel.stmd , replace
                    
                    markstat using fuel,  
                    markstat using fuel, pdf
                    set tracedepth 20
                    set tracehilite docx
                    set trace on
                    markstat using fuel, docx
                    and as you can imagine the output outstrips the max `scrollbufsize` , but here's the relevant output where the error occurs. I'm not sure what the issue is though - maybe this will help you diagnose whether it's something in the markstat program vs. something I've got misconfigured ?
                    Thanks again for the help!


                    Code:
                        - }
                        - confirm file "`filename'.smcl"
                        = confirm file "fuel.smcl"
                        - local skip = "`format'" == "docx" | "`format'" == "markdown"
                        = local skip = "docx" == "docx" | "docx" == "markdown"
                        - if `skip' {
                        = if 1 {
                        - quietly copy "`filename'.md" "`filename'.pdx", replace
                        = quietly copy "fuel.md" "fuel.pdx", replace
                        - }
                        - else {
                          if "`theme'" != "" local optionaltheme theme(`theme')
                          local options format(`format') `optionaltheme' `incremental' `bibliography' `mathjax' `bundle'
                          _pandoc using "`filename'", `options'
                          }
                        - mata weave(`"`filename'"', "`format'", "`plain'" == "plain")
                        = mata weave(`"fuel"', "docx", "" == "plain")
                        - if "`format'" == "docx" {
                        = if "docx" == "docx" {
                        - _pandoc using "`filename'", format(docx) `bibliography'
                        = _pandoc using "fuel", format(docx) 
                          ---------------------------------------------------------------------- begin markstat._pandoc ---
                          - syntax using/ [, format(string) theme(string) incremental BIBliography mathjax bundle]
                          - local filename `using'
                          = local filename fuel
                          - if "`bibliography'" == "bibliography" {
                          = if "" == "bibliography" {
                            local args --filter pandoc-citeproc
                            }
                          - local args `args' -f markdown -t `format'
                          = local args  -f markdown -t docx
                          - if "`format'" == "beamer" & "`theme'" != "" {
                          = if "docx" == "beamer" & "" != "" {
                            local args `args' -V theme=`theme'
                            }
                          - if "`format'" == "s5" {
                          = if "docx" == "s5" {
                            if "`theme'" == "" local theme default
                            mata: unzipS5()
                            mata: st_local("s5", getFolder(findFile("s5/`theme'/slides.css")))
                            confirm file "`s5'/slides.js"
                            local args `args' -V s5-url="`s5'"
                            }
                          - if "`incremental'" == "incremental" {
                          = if "" == "incremental" {
                            local args `args' -i
                            }
                          - if "`mathjax'" == "mathjax" local mj --mathjax
                          = if "" == "mathjax" local mj --mathjax
                          - if "`bundle'" == "bundle" & inlist("`format'", "html", "s5") {
                          = if "" == "bundle" & inlist("docx", "html", "s5") {
                            local args `args' --self-contained
                            if "`mj'" != "" {
                            whereis(mathjax)
                            local mj `mj'="`r(mathjax)'"
                            }
                            }
                          - local args `args' `mj'
                          = local args -f markdown -t docx 
                          - if "`format'" == "docx" {
                          = if "docx" == "docx" {
                          - mata: st_local("docx", findFile("markstat.docx"))
                          - confirm file "`docx'"
                          = confirm file "/Users/ebooth/Library/Application Support/Stata/ado/plus/m/markstat.docx"
                    file /Users/ebooth/Library/Application Support/Stata/ado/plus/m/markstat.docx not found
                            local args `args' --reference-doc="`docx'"
                            }
                          ------------------------------------------------------------------------ end markstat._pandoc ---
                          }
                        ------------------------------------------------------------------------ end markstat._markstat ---
                      - if _rc > 0 _closeAllFiles
                    Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

                    Comment


                    • #25
                      See the discussion here and here for more on the subject of markstat installtion.

                      Comment


                      • #26
                        In case anyone is interested, I added syntax highlighting for the dynamic tags provided with the dyntext and dyndoc commands to the Stata syntax highlighting for the Atom text editor. I also explain how to use dyntext in conjunction with Pandoc to get PDF output.

                        I could add highlighting for Markstat easily if people are interested. If anyone is, submit an issue on the Github repository.

                        Comment

                        Working...
                        X