Dear Statalist users,
I kindly need some help for dealing with the issue below:
I am trying to list and compare numerous variables (more than 200) coming from different CRFs using loops.
After successful programming steps, I have the following (abstract) dataset (NOV stands for NOVember data and APR for APRil data):
-------------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------------------------------
pid int %8.0g __SubjectKey
crf str12 %12s __FormOID
priorvteAPR byte %8.0g PRIORVTE
fmhisvteAPR byte %8.0g FMHISVTE
hiscancAPR byte %8.0g HISCANC
priorvteNOV byte %8.0g PRIORVTE
fmhisvteNOV byte %8.0g FMHISVTE
hiscancNOV byte %8.0g HISCANC
All I want to do is the following :
(1) list matched pairs when values are equal
(2) list matched pairs when values are NOT equal
by matched (or desirable) pairs, I mean priorvteAPR vs. priorvteNOV etc , avoiding output with priorvteAPR vs. fmhisvteNOV
The code I use for this:
lookfor NOV
local nov `r(varlist)' //need to be executed immediately after LOOKFOR
lookfor APR
local apr `r(varlist)' //need to be executed immediately after LOOKFOR
//works FOR EQUAL but not what I need (gives every possible pair)
foreach n of local nov{
foreach a of local apr{
cap nois list `n' `a' if `n'==`a' & `n'==`a'!=. in 1/7, abbr(20) noobs clean
}
}
//works FOR EQUAL and it is what I need (gives with matched pairs only)
foreach n of local nov{
foreach a of local apr{
cap nois list `n' `a' ///
if `n'==`a' & `n'==`a'!=. & ///
(substr("`n'", 2, length("`n'")-5)== ///
substr("`a'", 2,length("`a'")-5)) in 1/12, abbr(22) noobs clean
}
}
However, whatever I have tried to list matched pairs for when values are not equal between NOVember and APRil pairs, did not work!
Any ideas would be much appreciated.
Thank you
George
I kindly need some help for dealing with the issue below:
I am trying to list and compare numerous variables (more than 200) coming from different CRFs using loops.
After successful programming steps, I have the following (abstract) dataset (NOV stands for NOVember data and APR for APRil data):
-------------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------------------------------
pid int %8.0g __SubjectKey
crf str12 %12s __FormOID
priorvteAPR byte %8.0g PRIORVTE
fmhisvteAPR byte %8.0g FMHISVTE
hiscancAPR byte %8.0g HISCANC
priorvteNOV byte %8.0g PRIORVTE
fmhisvteNOV byte %8.0g FMHISVTE
hiscancNOV byte %8.0g HISCANC
All I want to do is the following :
(1) list matched pairs when values are equal
(2) list matched pairs when values are NOT equal
by matched (or desirable) pairs, I mean priorvteAPR vs. priorvteNOV etc , avoiding output with priorvteAPR vs. fmhisvteNOV
The code I use for this:
lookfor NOV
local nov `r(varlist)' //need to be executed immediately after LOOKFOR
lookfor APR
local apr `r(varlist)' //need to be executed immediately after LOOKFOR
//works FOR EQUAL but not what I need (gives every possible pair)
foreach n of local nov{
foreach a of local apr{
cap nois list `n' `a' if `n'==`a' & `n'==`a'!=. in 1/7, abbr(20) noobs clean
}
}
//works FOR EQUAL and it is what I need (gives with matched pairs only)
foreach n of local nov{
foreach a of local apr{
cap nois list `n' `a' ///
if `n'==`a' & `n'==`a'!=. & ///
(substr("`n'", 2, length("`n'")-5)== ///
substr("`a'", 2,length("`a'")-5)) in 1/12, abbr(22) noobs clean
}
}
However, whatever I have tried to list matched pairs for when values are not equal between NOVember and APRil pairs, did not work!
Any ideas would be much appreciated.
Thank you
George
Comment