/******************************************************************************* log: 2022-04-21 nhb Created *******************************************************************************/ //OFF cls cd C:/Users/sttp/Documents/nhb/STATA/StataHacks/docs/log2markup/ set linesize 255 * logname must be the name of this (current) do-file local logname log2markup_example * remove the two slashes (//) below and no logging/use of -log2markup- is done local logging //* local datestamp: display %td_CCYY-NN-DD date(c(current_date), "DMY") `logging' capture log close `logging' log using "output/`logname'.log", replace //ON /*** --- title: -log2markup- example author: - | Niels Henrik Bruun \ Unit of Clinical Biostatistics, \ Aalborg University Hospital, Aalborg, Denmark ***/ /****/display `"date: `datestamp'"' /*** abstract: | **Background** Infant mortality rates and birth defect rates are very high for low birth weight babies. A woman's behaviour during pregnancy can greatly alter the chances of carrying the baby to term. \ **Aim** To identify if smoking during pregnancy is associated with giving birth to a low birth weight baby. \ **Results** Smoking during pregnancy increases the risk for birthweights below 2500g both crude and adjusted for age and race. It is only white mothers, who have a higher risk. ... # Data ## Outcomes Two binary variables for birthweight below 1500g and 2500g. ## Exposure Smoking during pregnancy is the exposure. ## Counfounders The variables for mothers age and race are considered a confounder. ## Data management ***/ /**/use low bwt age race smoke using "http://www.stata-press.com/data/r12/hospid2.dta", clear /**/rename low bwlt2500 /**/generate bwlt1500 = bwt < 1500 if !missing(bwt) /**/order bwlt1500, before(bwlt2500) /**/label variable bwlt1500 "birthweight < 1500g" /**/label variable bwlt2500 "birthweight < 2500g" /**/label define no_yes 0 "No" 1 "Yes" /**/label values bwlt* no_yes /**/label define smoke 0 "No" 1 "Yes" /**/label values smoke smoke /**/label data "From: http://www.stata-press.com/data/r12/hospid2.dta" /*** # Results ## Data description ***/ /****/basetable smoke age(%6.1f, iqi) race(c), style(md) nopvalue /// title(**Table 1:** The variables) /*** ## Effect measurements ***/ /****/regmat, outcome(bwlt2500 bwlt1500) exposure(i.smoke) /// adjustments("" " age i.race") drop(se p) labels eform /// style(md) title(`"**Table 2:** Crude and adjusted (age, race) effects."' /// `"Smoking during pregnancy increases the risk for birthweights below"' /// `"2500g both crude and adjusted for age and race."' /// ) btext(RR) names("Crude", "Adj"): poisson, vce(robust) /*** ## sub analyses ***/ /**/emc, at(14(2)28) yline(0) ytitle(log(RR)) name(fig1, replace): poisson bwlt2500 smoke age, vce(robust) /**/graph export output/fig1.png, width(8000) replace /*** ![**Figure 1: Effect modification by age.**](output/fig1.png) ***/ /**/poisson bwlt2500 i.smoke##i.race, vce(robust) /**/margins r.smoke, over(race) /**/marginsplot, yline(0) ytitle(log(RR)) title("") name(fig2, replace) /**/graph export output/fig2.png, width(8000) replace /*** ![**Figure 2: Effect modification by race.** It is only white mothers, who have a higher risk.](output/fig2.png) ***/ ******************************************************************************** *** The end ******************************************************************** ******************************************************************************** //OFF `logging' log close * Creating the markup file using -log2markup- `logging' log2markup using "output/`logname'.log", replace extension(txt) * Usually the log file is not needed, only the markup file `logging' rm "output/`logname'.log" //ON