Skip to content

Commit

Permalink
fixed parse yreg
Browse files Browse the repository at this point in the history
  • Loading branch information
anddis committed Jun 15, 2018
1 parent dba68da commit 577667d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# med4way
### A Stata command for the 4-way decomposition using parametric regression models

- Current version: `2.2.1`
- Release date: `19sep2017`
- Current version: `2.2.2`
- Release date: `14jun2018`

---

Expand All @@ -21,13 +21,13 @@ Note: the 4-way decomposition holds without any assumptions about confounding. H

- To install the current version of `med4way` directly from GitHub, run:
```Stata
net install med4way, from("https://raw.githubusercontent.com/anddis/med4way/master/")
```
net install med4way, from("https://raw.githubusercontent.com/anddis/med4way/master/") replace
```
from within a web-aware Stata (version 13+).

- For older versions of Stata, download and extract the [zip file](https://github.com/anddis/med4way/archive/master.zip) and then run:
```Stata
net install med4way, from(mydir)
net install med4way, from(mydir) replace
```
from within Stata, where *mydir* is the directory that containes the extracted files.

Expand Down
42 changes: 16 additions & 26 deletions med4way.ado
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
*! Hello, I'm med4way.ado
*! v2.2.1 - 19sep2017
*! v2.2.2 - 14jun2018

/*
Previous versions:
v2.2.1 - 19sep2017
v2.2.0 - 31jul2017
v2.1.1 - 28jul2017
v2.1.0 - 26jul2017
Expand Down Expand Up @@ -56,27 +57,15 @@ program define med4way, eclass
_get_diopts diopts, `options'

//parse yreg
gettoken yregx yreg : yreg, parse(",")
gettoken comma yreg : yreg
if length("`comma'") > 1 {
local 0 = substr("`comma'",2,.) + "`opt'"
local comma = substr("`comma'", 1, 1)
}
gettoken dist opt : yreg

local yregx = trim(`"`yregx'"')
local opt = trim(`"`opt'"')
if `"`yregx'"'!="" & `"`opt'"'=="" {
if `"`comma'"'=="" | (`"`comma'"'=="," & `"`dist'"'=="") {
local yreg `"`yregx'"'
local dist ""
}

if `"`comma'"'=="," & `"`dist'"'!="" {
local yreg `"`yregx'"'
local dist `"`dist'"'
}
}
gettoken yreg_1 yreg_2 : yreg, parse(",")
gettoken comma opt : yreg_2, parse(",")
// if length("`comma'") > 1 { unnecessary
// local comma = trim("`comma'")
// }

local yreg = trim(`"`yreg_1'"')
local dist = trim(`"`opt'"')


local l = length("`yreg'")
if substr("linear", 1, max(3,`l')) == "`yreg'" {
Expand Down Expand Up @@ -263,7 +252,7 @@ program define med4way, eclass
local wrnngtxt `wrnngtxt' 2
}
else {
qui logit `yvar' if `touse'
qui logit_10 `yvar' if `touse'
local prev = invlogit(_b[_cons])*100
if `prev' > 10 {
local wrnngtxt `wrnngtxt' 1
Expand Down Expand Up @@ -300,7 +289,7 @@ program define med4way, eclass
continue, break
}
}
//all the 8 suggested names have been used by existing variables, give an error message
//all the 8 suggested names have been used by existing variables, throw an error message
if _rc {
display as error "Error: The command needs to create an interaction variable " /*
*/ "with one of the following names: `inter_var_names', " /*
Expand Down Expand Up @@ -377,7 +366,7 @@ program define med4way, eclass
}

display _n(1) as text "-> Summary" _n(1)
display _col(4) as text "Outcome (yvar):" _col(24) as res "`=cond("`survoutcome'"=="true", "[ survival outcome ]", "`yvar'")'"
display _col(4) as text "Outcome (yvar):" _col(24) as res "`=cond("`survoutcome'"=="true", "_t", "`yvar'")'"
display _col(4) as text "Treatment (avar):" _col(24) as res "`avar'"
display _col(4) as text "Mediator (mvar):" _col(24) as res "`mvar'"
display _col(4) as text "Covariates (cvars):" _col(24) as res "`=cond(`nc'==0, "[ none ]", "`cvar'")'" _n(1)
Expand Down Expand Up @@ -499,7 +488,7 @@ program define med4way, eclass
ereturn scalar a1 = `a1'
ereturn scalar m = `m'

if "`bootstrap'"=="true" {
if "`bootstrap'"=="true" { // bootstrap stuff
ereturn scalar N_reps = `reps'
ereturn local prefix = "bootstrap"
ereturn local vcetype = "Bootstrap"
Expand All @@ -523,6 +512,7 @@ program define med4way, eclass
}
ereturn matrix b_bs = `b_bs'
}

if `nc' > 0 {
ereturn matrix c = `cmatrix'
}
Expand Down
4 changes: 2 additions & 2 deletions med4way.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ d A.Discacciati, A.Bellavia, L.Valeri
d
d After installation, see help med4way
d
d Current version: 2.2.1
d Distribution-Date: 19sep2017
d Current version: 2.2.2
d Distribution-Date: 14jun2018
d
f med4way.ado
f med4way_engine.ado
Expand Down
2 changes: 1 addition & 1 deletion med4way.sthlp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{smcl}
{* *! version 2.2.1 19sep2017}{...}
{* *! version 2.2.2 14jun2018}{...}

{cmd:help med4way}
{hline}
Expand Down

0 comments on commit 577667d

Please sign in to comment.