{"id":52,"date":"2014-03-21T15:46:02","date_gmt":"2014-03-21T15:46:02","guid":{"rendered":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/?p=52"},"modified":"2025-02-26T13:21:39","modified_gmt":"2025-02-26T13:21:39","slug":"keeping-good-records","status":"publish","type":"post","link":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/2014\/03\/21\/keeping-good-records\/","title":{"rendered":"Keeping good records"},"content":{"rendered":"<p style=\"text-align: left\" align=\"center\">No properly managed statistical analysis would use results that were calculated interactively because of the difficulty of reproducing them when you do not have a written record of exactly what was done. For this reason, Stata users usually store their commands in do files.<\/p>\n<p style=\"text-align: left\">When running WinBUGS from within Stata we need to create four text files that store the model, data, initial values and batch script. The data and initial values can be written to a file using the \u2013<b>wbslist<\/b>&#8211; command and the script file can be created using \u2013<b>wbsscript-<\/b>, both of these are described in detail in the book, \u2018<i>Bayesian Analysis with Stata<\/i>\u2019 that is due to be published shortly. Alternatively, the files could be prepared using the commands described in the Stata Journal article <a href=\"http:\/\/www.stata-journal.com\/article.html?article=st0115\">http:\/\/www.stata-journal.com\/article.html?article=st0115<\/a>. This leaves the model file, which has to be written in WinBUGS syntax, so it is usually created separately using a text editor. Here lies the problem, the do file will not contain a record of the contents of the model file and when you return to the analysis after a long gap, it can be difficult to determine exactly what form the model file had when you last ran the analysis, especially if, like me, you have the bad habit of calling all model files, model.txt.<\/p>\n<p>Ideally we would like the WinBUGS model to be stored as part of the do file, but as it is in WinBUGS syntax it will not run in Stata and so needs to be commented out. For a long time this is what I did. I would create the do file and the model file separately, then copy the model and store it within the do file, commenting it out using\u00a0 \/* \u2026. *\/.<\/p>\n<p>Recently I developed a slightly different way of achieving the same end. I wrote a program that I called <strong>tomodel; <\/strong>this command copies\u00a0commented out code to a text file. Originally I\u00a0had no\u00a0intention of\u00a0making this command public, but the more I used it, the more I realized that it would be useful to anyone running WinBUGS from within Stata.\u00a0So I decided to rename the command\u00a0&#8211;<b>wbsmodel<\/b>&#8211; and make it part of the downloadable family of wbs commands. This new command reads the contents of a commented out block of text that is stored in a do file and copies it to a text file.\u00a0With this command,\u00a0it is possible to\u00a0write the model as part of\u00a0the do file, comment it out and precede it with a call to wbsmodel. When the do file runs the model file is created afresh from the commented out text and thus has exactly the contents that you see in the do file. For instance, a piece of Stata code might read,<\/p>\n<p><span style=\"color: #000080\"><b>\u2026.<\/b><\/span><\/p>\n<p><span style=\"color: #000080\"><b>wbsmodel thisfile.do model.txt<\/b><\/span><\/p>\n<p><span style=\"color: #000080\"><b>\/*<\/b><\/span><\/p>\n<p><span style=\"color: #000080\"><b>model {<\/b><\/span><\/p>\n<p><span style=\"color: #000080\"><b>\u00a0\u00a0 for( i in 1:10) {<\/b><\/span><\/p>\n<p><span style=\"color: #000080\"><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 y[i] ~ dnorm(mu,1)<\/b><\/span><\/p>\n<p><span style=\"color: #000080\"><b>\u00a0\u00a0 }<\/b><\/span><\/p>\n<p><span style=\"color: #000080\"><b>\u00a0\u00a0 mu ~ dnorm(0,0.001)<\/b><\/span><\/p>\n<p><span style=\"color: #000080\"><b>}<\/b><\/span><\/p>\n<p><span style=\"color: #000080\"><b>*\/<\/b><\/span><\/p>\n<p><span style=\"color: #000080\"><b>\u2026.<\/b><\/span><\/p>\n<p>The two arguments that follow the command word are the name of the do file that I am working with (thisfile.do) and the name of the text file\u00a0to which\u00a0I want the WinBUGS code written (model.txt). The command works by re-reading the do file\u00a0 until it locates the command line and then\u00a0it copies the\u00a0subsequent commented out text to the named file.<\/p>\n<p>The do file runs normally in Stata and I have an exact record of the model file that I used for that analysis. What is more, if I need to edit the model file, all I need to do is to edit the commented out lines within my do file and then re-run it.<\/p>\n<p>All of the commands describd in the forthcoming book &#8216;<em>Bayesian Analysis with Stata<\/em>&#8216; can be net installed from <a href=\"http:\/\/stata-press.com\/data\/bas\">http:\/\/stata-press.com\/data\/bas<\/a> . At the time\u00a0of preparing this posting \u00a0(19th March 2014)\u00a0the command is still\u00a0net installed\u00a0as <strong>tomodel<\/strong> but I have asked for it to be renamed <strong>wbsmodel<\/strong> and for it to be added to the wbs family and I expect this to happen soon. Instructions for running the downloadable commands are contained in the help files and you can obtain a pdf of the contents of those help files\u00a0by downloading\u00a0my\u00a0<a href=\"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/files\/2014\/03\/manual.pdf\">manual<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>No properly managed statistical analysis would use results that were calculated interactively because of the difficulty of reproducing them when you do not have a written record of exactly what was done. For this reason, Stata users usually store their commands in do files. When running WinBUGS from within Stata we need to create four [&hellip;]<\/p>\n","protected":false},"author":134,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4,5],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-stata","tag-winbugs"],"_links":{"self":[{"href":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/wp-json\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/wp-json\/wp\/v2\/users\/134"}],"replies":[{"embeddable":true,"href":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/wp-json\/wp\/v2\/comments?post=52"}],"version-history":[{"count":5,"href":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":59,"href":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/wp-json\/wp\/v2\/posts\/52\/revisions\/59"}],"wp:attachment":[{"href":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staffblogs.le.ac.uk\/bayeswithstata\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}