
* --------------------------------------------------------------
* Stata do-file to article published in Survey Research Methods
* --------------------------------------------------------------
* Willingness to use mobile technologies for data collection
* in a probability household panel
* --------------------------------------------------------------
* Authors:
* Alexander Wenz (University of Essex)
* Annette Jäckle (University of Essex)
* Mick P. Couper (University of Michigan)
* --------------------------------------------------------------

* -------------------
* I. DATA MANAGEMENT
* -------------------

sysdir set PLUS d:\home\awenz\ado\stbplus

* sample files may have more than one record per sample member if they moved HHs:
* keep one record with sample member's final HH location
cd "I:\Alex_Annette_Mick\data\UKDA-6849-stata13_se\stata13_se\indsamp"
local vlist b c d e f g h
foreach x of local vlist {
use `x'_indsamp_ip, clear
keep pidp `x'_ivfio `x'_finloc
keep if `x'_finloc == 1
save `x'_indsamp, replace
}

* load dataset
cd "I:\Alex_Annette_Mick\data\UKDA-6849-stata13_se\stata13_se"
use i_indresp_ip, clear 

* compute analysis base
tab i_netpuse if i_netpuse != -7 // respondents who gave full interview
tab i_scac if i_scac != -7 & i_indmode == 1 & i_scac >= 4 // CAPI respondents who refused or were not able to do self-completion section
tab i_indmode if i_indmode !=-7 & i_indmode == 2 // CATI respondents
tab i_netpuse if i_netpuse != 0 & i_indmode == 3 | (i_indmode == 1 & i_scac >= 1 & i_scac <= 3) // respondents without Internet access
tab i_scsmtphone if i_scsmtphone != -8 & i_scsmtphone != -7 // respondents who received questions on mobile device access
tab i_scsmtphone i_sctablet if i_scsmtphone != -8 & i_scsmtphone != -7 // respondents who received questions on willingness
tab i_scsmtphone i_sctablet if i_scsmtphone == 1 | i_sctablet == 1, cell // device use among respondents

* compute numbers for actual device use in Innovation Panel web survey
gen device = 1 if i_deviceused == 1
replace device = 2 if i_deviceused == 2 | i_deviceused == 3 | i_deviceused == 4
replace device = 3 if i_deviceused == 5
replace device = 4 if i_deviceused == 8

label def devicel 1 "PC/Laptop" 2 "Tablet" 3 "Smartphone" 4 "Other"
label val device devicel

tab device if i_indmode == 3
drop device

* declare sample design
svyset, clear
svyset i_psu [pweight=i_indscip_xw], strata(i_strata)

* compute willingness distributions, with missing values
* -- not accounted for sample design
foreach x of var i_scwill*sp i_scwill*tb {
	tab `x' if `x' != -8 & `x' != -7
}

* -- accounted for sample design 
foreach x of var i_scwill*sp i_scwill*tb {
	svy: tab `x' if `x' != -8 & `x' != -7
}

* declare missing values
foreach x of var i_scdsktcomp-i_scwrrymod6 i_fcacon1 i_disdif6 i_disdif3 {
	replace `x' = . if `x' < 0
}

* recode willingness variable
* -- smartphone
// recode variable so that higher values = higher levels of willingness
local willoriginal "i_scwill1sp i_scwill2sp i_scwill3sp i_scwill4sp i_scwill5sp i_scwill6sp i_scwill7sp i_scwill8sp"
local willnew "will1sp will2sp will3sp will4sp will5sp will6sp will7sp will8sp"
forvalues i = 1/8 {
local a : word `i' of `willoriginal'
local b : word `i' of `willnew'
gen `b' = abs(`a'-5)
}

// recode into dummy variable: 1 Very or somewhat willing, 0 A little or not at all willing
local willoriginal "i_scwill1sp i_scwill2sp i_scwill3sp i_scwill4sp i_scwill5sp i_scwill6sp i_scwill7sp i_scwill8sp"
local willnew "will1spdum will2spdum will3spdum will4spdum will5spdum will6spdum will7spdum will8spdum"
forvalues i = 1/8 {
local a : word `i' of `willoriginal'
local b : word `i' of `willnew'
gen `b' = 1 if `a' == 1 | `a' == 2
replace `b' = 0 if `a' == 3 | `a' == 4
}

* -- tablet
// recode variable so that higher values = higher levels of willingness
local willoriginal "i_scwill1tb i_scwill2tb i_scwill3tb i_scwill5tb i_scwill8tb"
local willnew "will1tb will2tb will3tb will5tb will8tb"
forvalues i = 1/5 {
local a : word `i' of `willoriginal'
local b : word `i' of `willnew'
gen `b' = abs(`a'-5)
}

// recode into dummy variable: 1 Very or somewhat willing, 0 A little or not at all willing
local willoriginal "i_scwill1tb i_scwill2tb i_scwill3tb i_scwill5tb i_scwill8tb"
local willnew "will1tbdum will2tbdum will3tbdum will5tbdum will8tbdum"
forvalues i = 1/5 {
local a : word `i' of `willoriginal'
local b : word `i' of `willnew'
gen `b' = 1 if `a' == 1 | `a' == 2
replace `b' = 0 if `a' == 3 | `a' == 4
}

* recode explanatory variables
// frequency of use: smartphone
gen dailyusesp = 1 if i_scfrqusesp == 1
replace dailyusesp = 0 if i_scfrqusesp > 1 & i_scfrqusesp != .
label var dailyusesp "Use smartphone every day"
label def dailyusel 1 "Every day" 0 "Less than every day"
label val dailyusesp dailyusel

// frequency of use: tablet
gen dailyusetb = 1 if i_scfrqusetb == 1
replace dailyusetb = 0 if i_scfrqusetb > 1 & i_scfrqusetb != .
label var dailyusetb "Use tablet every day"
label val dailyusetb dailyusel

// number of activities: smartphone
local willsp "i_scbrowsesp i_scemailsp i_scphotosp i_scsmlooksp i_scsmpostsp i_scbuysp i_scbanksp i_scinstalsp i_scgpssp i_scblutthsp i_scgamessp i_scstreamsp"
local actsp "browse email camera smlook smpost buy bank install gps blue games stream"
forvalues i = 1/12 {
local a : word `i' of `willsp'
local b : word `i' of `actsp'
gen `b' = abs(`a' - 2)
}
egen genactsp = rowtotal(browse-stream), missing
label var genactsp "Number of activities on smartphone"

// number of activities: tablet
local willtb "i_scbrowsetb i_scemailtb i_scphototb i_scsmlooktb i_scsmposttb i_scbuytb i_scbanktb i_scinstaltb i_scgpstb i_scblutthtb i_scgamestb i_scstreamtb"
local acttb "browsetb emailtb cameratb smlooktb smposttb buytb banktb installtb gpstb bluetb gamestb streamtb"
forvalues i = 1/12 {
local a : word `i' of `willtb'
local b : word `i' of `acttb'
gen `b' = abs(`a' - 2)
}
egen genacttb = rowtotal(browsetb-streamtb), missing
label var genacttb "Number of activities on tablet"

// self-reported skill: smartphone
gen ablesp = i_scskillsp
label var ablesp "Self-rated skill on smartphone"

// self-reported skill: tablet
gen abletb = i_scskilltb
label var abletb "Self-rated skill on tablet"

// physical limitations
gen sightpr = 1 if i_disdif6 == 1
replace sightpr = 0 if i_disdif6 == 0
label var sightpr "Vision problems"

gen dextpr = 1 if i_disdif3 == 1
replace dextpr = 0 if i_disdif3 == 0
label var dextpr "Dexterity problems"

gen physlim = 1 if sightpr == 1 | dextpr == 1
replace physlim = 0 if sightpr == 0 & dextpr == 0
label var physlim "Physical limitations"
label def duml 1 "Yes" 0 "No"
label val physlim duml

// WiFi access at home
gen wifi = 1 if i_schomewifi == 1
replace wifi = 0 if i_schomewifi == 2
label var wifi "WiFi access"
label val wifi duml

// type of smartphone contract
gen dataplan = 1 if i_sccontrtsp == 2
replace dataplan = 0 if i_sccontrtsp == 1 | i_sccontrtsp == 3
label var dataplan "Type of smartphone contract"
label def dataplanl 1 "Pay-as-you-go plan" 0 "Fixed data plan or WiFi only"
label val dataplan dataplanl

// time constraints
* -- employment and work hours
gen longwork = 1 if (i_jbsemp == 1 & i_jbhrs > 40) | (i_jbsemp == 2 & i_jshrs > 40)
replace longwork = 0 if (i_jbsemp == -8) | (i_jbsemp == 1 & i_jbhrs <= 40 & i_jbhrs > 0) | (i_jbsemp == 2 & i_jshrs <= 40 & i_jshrs > 0)

* -- commuting time
gen longcommute = 1 if (i_jbttwt > 60) | (i_jsttwtb > 60)
replace longcommute = 0 if (i_jbttwt >= 0 & i_jbttwt <= 60) | (i_jsttwtb >= 0 & i_jsttwtb <= 60)

gen busy = 0
replace busy = 1 if longwork == 1 | longcommute == 1
label var busy "Long working or commuting hours"

* -- children or caring responsibilities [number of children in HH, source: HH questionnaire]
merge m:1 i_hidp using i_hhresp_ip, keepusing(i_nch02_dv i_nch34_dv)
keep if _merge == 1 | _merge == 3
drop _merge
gen caring = 0
replace caring = 1 if i_nch02_dv > 0 | i_nch34_dv | i_carechk == 1
label var caring "Young children or caring responsibilities"

gen timeconstraint = 1 if busy == 1 | caring == 1
replace timeconstraint = 0 if busy == 0 & caring == 0
label var timeconstraint "Time constraints"
label val timeconstraint duml

// security concerns
egen scworrymeansp = rowmean(i_scworry1-i_scworry8)
label var scworrymeansp "Security concerns"

// item-nonresponse
destring, replace
egen miscount = anycount(i_jbstat-i_sclfsato), values(-1 -2 -9) // for each respondent: count items with missing values
unab vars : i_jbstat-i_sclfsato // count items in varlist: 817
di `: word count `vars''
egen ineligcount = anycount(i_jbstat-i_sclfsato), values(-8) // for each respondent: count ineligible items
gen misrate = miscount / (817 - ineligcount) // for each respondent: calculate item-missing rate

gen itemnr = 1 if misrate > 0 
replace itemnr = 0 if misrate == 0
label var itemnr "Item-nonresponse"
label def itemnrl 1 ">= 1 items missing" 0 "No items missing"
label val itemnr itemnrl

// consent to data linkage
gen linkage = 1 if i_fcacon1 == 1
replace linkage = 0 if i_fcacon1 == 2
label var linkage "Consent to data linkage"
label val linkage duml

// mode of data collection
gen web = 1 if i_indmode == 3
replace web = 0 if i_indmode == 1 | i_indmode == 2
label var web "Mode of interview"
label def webl 1 "Web" 0 "Face-to-face"
label val web webl

// number of eligible waves [source: sample file]
* merge sample file Wave 1
merge 1:1 pidp using a_indall_ip, keepusing(a_ivfio)
keep if _merge == 1 | _merge == 3
drop _merge

* merge sample files Wave 2-8
cd "I:\Alex_Annette_Mick\data\UKDA-6849-stata13_se\stata13_se\indsamp"
local vlist b c d e f g h
foreach x of local vlist {
merge 1:1 pidp using `x'_indsamp, keepusing(`x'_ivfio)
keep if _merge == 1 | _merge == 3
drop _merge
}

egen eligible = anycount(*_ivfio), values(1 2 3 9 10 11 14 15 16 50 53 57) // 1 full interview, 2 proxy interview, 3 cati interview, 9 lost capi interview, 10 refusal, 11 other non-intvw, 14 ill/away during survey period, 15 too infirm/elderly, 16 language difficulties, 50 refusal/non-int hh, 53 non-cont/non-int hh, 57 ill/away during survey period

gen eligibleC = 1 if eligible >= 1 & eligible <= 3
replace eligibleC = 2 if eligible >= 4 & eligible <= 6
replace eligibleC = 3 if eligible >= 7 & eligible <= 9

label var eligibleC "Number of eligible waves"
label define eligibleCl 1 "1-3" 2 "4-6" 3 "7-9"
label values eligibleC eligibleCl

// prior panel response rate [source: sample file]
egen fullinterview = anycount(*_ivfio), values(1 3 9) // 1 full interview, 3 cati interview (in wave 1), 9 lost capi interview 
gen propinterview = fullinterview / eligible
label var propinterview "Prior panel response rate"

// gender
gen female = 1 if i_sex == 2
replace female = 0 if i_sex == 1
label var female "Female"
label def femalel 1 "Female" 0 "Male"
label val female femalel

// age
gen age = i_pdvage
label var age "Age"

gen age2 = age^2
label var age2 "Age-squared"

// education
gen edu = 1 if i_hiqual_dv == 1 | i_hiqual_dv == 2
replace edu = 2 if i_hiqual_dv == 3
replace edu = 3 if i_hiqual_dv == 4
replace edu = 4 if i_hiqual_dv == 5 | i_hiqual_dv == 9
label var edu "Education"
label define edul 1 "Higher degree" 2 "A-level" 3 "GCSE" 4 "No or other qualification", replace
label values edu edul

// labour force status
gen empl = 1 if i_jbstat == 1 | i_jbstat == 2
replace empl = 0 if i_jbstat > 2
label var empl "Labour force status"
label def empll 1 "In work" 0 "Not in work"
label val empl empll

// individual monthly gross income
gen inc = i_fimngrs_dv
label var inc "Individual monthly gross income"
 
gen incln = ln(inc+1)
label var incln "Individual monthly gross income (ln)"

* -- housing tenure [source: HH questionnaire]
cd "I:\Alex_Annette_Mick\data\UKDA-6849-stata13_se\stata13_se"

merge m:1 i_hidp using i_hhresp_ip, keepusing(i_hsownd)
keep if _merge == 1 | _merge == 3
drop _merge
gen owned = 1 if i_hsownd == 1 | i_hsownd == 2 | i_hsownd == 3
replace owned = 0 if i_hsownd >= 4
label var owned "Own house"
label def ownedl 1 "Has own house" 0 "Not own house"
label val owned ownedl


* ------------------
* II. DATA ANALYSIS
* ------------------

* DESCRIPTIVE STATISTICS OF RESPONDENT CHARACTERISTICS (TABLE 2)

* -- smartphone
// categorical variables
foreach x of var dailyusesp physlim wifi dataplan timeconstraint itemnr linkage web eligibleC female edu empl owned {
	svy: tab `x' if i_scsmtphone == 1
}
// continuous variables
foreach x of var genactsp ablesp scworrymeansp propinterview age inc {
	svy: mean `x' if i_scsmtphone == 1
	estat sd
}

* -- tablet
// categorical variables
foreach x of var dailyusetb physlim wifi timeconstraint itemnr linkage web eligibleC female edu empl owned {
	svy: tab `x' if i_sctablet == 1
}
// continuous variables - original strata
foreach x of var genacttb abletb scworrymeansp propinterview age inc {
	svy: mean `x' if i_sctablet == 1
	estat sd
}
* standard errors are missing because some strata have single PSUs due to missing values

// check which strata have single PSUs
svydes genacttb abletb scworrymeansp propinterview age inc if i_sctablet == 1, single

// collapse strata with single PSUs
gen newstr = i_strata
gen newpsu = i_psu
replace newpsu = i_psu + 57 if i_strata == 56
replace newstr = 57 if i_strata == 56

// declare sample design with collapsed strata
svyset, clear
svyset newpsu [pweight=i_indscip_xw], strata(newstr)
svydes

// continous variables - collapsed strata
foreach x of var genacttb abletb scworrymeansp propinterview age inc {
	svy: mean `x' if i_sctablet == 1
	estat sd
}


* RESEARCH QUESTION 1

* declare sample design with original strata
svyset, clear
svyset i_psu [pweight=i_indscip_xw], strata(i_strata)

* -- smartphone
// willingness distributions, with missing values (Table A1)
foreach x of varlist i_scwill*sp {
	svy: tab `x' if i_scsmtphone == 1, miss
}

// willingness distributions, without missing values
foreach x of varlist i_scwill*sp {
	svy: tab `x' if i_scsmtphone == 1
}

// stacked bar chart, without missing values (Figure 2)
keep pidp i_scwill*sp i_psu i_strata i_indscip_xw
rename (i_scwill*sp) (i_scwill*)
reshape long i_scwill, i(pid) j(type)
label define typel 1 "Questionnaire" 2 "Survey app" 3 "Tracking app" 4 "Text message survey" 5 "Camera" 6 "Accelerometer" 7 "GPS" 8 "Bluetooth", replace
label values type typel

gen will1=i_scwill==1 if !missing(i_scwill)
gen will2=i_scwill==2 if !missing(i_scwill)
gen will3=i_scwill==3 if !missing(i_scwill)
gen will4=i_scwill==4 if !missing(i_scwill)
replace will1=will1*100
replace will2=will2*100
replace will3=will3*100
replace will4=will4*100
gen willsum = will1 + will2

graph hbar (mean) will1 will2 will3 will4 [pweight=i_indscip_xw], over(type, sort(willsum) descending) stack legend(lab(1 "Very willing") lab(2 "Somewhat willing") lab(3 "A little willing") lab(4 "Not at all willing") colfirst) ytitle("Percent") ytick(0(10)100) scheme(s2mono) note("Note. Questionnaire, survey app, camera, accelerometer: N = 1,376." "Text message survey, GPS, bluetooth: N = 1,375. Tracking app: N = 1,374")
/*
Changed colors of bars:
Grayscale 7, Fill intensity: Full, Different outline color: Black
Grayscale 15, Fill intensity: Full, Different outline color: Black
Grayscale 11, Fill intensity: Full, Different outline color: Black
Grayscale 3, Fill intensity: Full, Different outline color: Black
*/

* -- tablet
* Note. Need to re-run code from DATA MANAGEMENT section (lines 31-323).

// willingness distributions, with missing values (Table A2)
foreach x of varlist i_scwill*tb {
	svy: tab `x' if i_sctablet == 1, miss
}

// willingness distributions, without missing values
foreach x of varlist i_scwill*tb {
	svy: tab `x' if i_sctablet == 1
}

// stacked bar chart, without missing values (Figure 3)
keep pidp i_scwill*tb i_indscip_xw
rename (i_scwill*tb) (i_scwill*)
reshape long i_scwill, i(pid) j(type)
label define typel 1 "Questionnaire" 2 "Survey app" 3 "Tracking app" 5 "Camera" 8 "Bluetooth", replace
label values type typel

gen will1=i_scwill==1 if !missing(i_scwill)
gen will2=i_scwill==2 if !missing(i_scwill)
gen will3=i_scwill==3 if !missing(i_scwill)
gen will4=i_scwill==4 if !missing(i_scwill)
replace will1=will1*100
replace will2=will2*100
replace will3=will3*100
replace will4=will4*100
gen willsum = will1 + will2

graph hbar (mean) will1 will2 will3 will4 [pweight=i_indscip_xw], over(type, sort(willsum) descending) stack legend(lab(1 "Very willing") lab(2 "Somewhat willing") lab(3 "A little willing") lab(4 "Not at all willing") colfirst) ytitle("Percent") ytick(0(10)100) scheme(s2mono) note("Note. Questionnaire, survey app, camera, bluetooth: N = 1,258. Tracking app: N = 1,257.")
/*
Changed colors of bars:
Grayscale 7, Fill intensity: Full, Different outline color: Black
Grayscale 15, Fill intensity: Full, Different outline color: Black
Grayscale 11, Fill intensity: Full, Different outline color: Black
Grayscale 3, Fill intensity: Full, Different outline color: Black
*/

// check how many respondents straight-lined in willingness question
foreach i in 1 2 3 4 {
	egen stwillsp`i' = anycount(i_scwill1sp-i_scwill8sp), values(`i') // smartphone
	replace stwillsp`i' = . if i_scsmtphone != 1
	egen stwilltb`i' = anycount(i_scwill1tb-i_scwill8tb), values(`i') // tablet
	replace stwilltb`i' = . if i_scsmtphone != 1	
}

foreach x of var stwillsp* stwilltb* {
	tab `x', mis
}
drop stwillsp* stwilltb*


* RESEARCH QUESTION 2

* Note. Re-run code from DATA MANAGEMENT section (lines 31-323).

// consistency of willingness, with missing values - ordinal willingness variables
local willsp "i_scwill1sp i_scwill2sp i_scwill3sp i_scwill5sp i_scwill8sp"
local willtb "i_scwill1tb i_scwill2tb i_scwill3tb i_scwill5tb i_scwill8tb"
forvalues i = 1/5 {
local a : word `i' of `willsp'
local b : word `i' of `willtb'
svy: tab `a' `b' if i_scsmtphone == 1 & i_sctablet == 1 & `a' > -1 & `b' > -1, row miss // accounted for sample design
tab `a' `b' if i_scsmtphone == 1 & i_sctablet == 1 & `a' > -1 & `b' > -1, row miss taub chi2 // not accounted for sample design to compute Kendall's tau-b (svy command does not support Kendall's tau-b)
}

// dichotomise willingness variables and create one consistency variable: 1 Willing on both devices, 2 Willing on smartphone, 3 Willing on tablet, 4 Not willing on either device
label define willconsl 1 "Willing on both devices" 2 "Willing on smartphone" 3 "Willing on tablet" 4 "Not willing on either device"  , replace
local willsp "i_scwill1sp i_scwill2sp i_scwill3sp i_scwill5sp i_scwill8sp"
local willtb "i_scwill1tb i_scwill2tb i_scwill3tb i_scwill5tb i_scwill8tb"
forvalues i = 1/5 {
local a : word `i' of `willsp'
local b : word `i' of `willtb'
gen willcons`i' = 1 if `a' <= 2 & `b' <= 2 & i_scsmtphone == 1 & i_sctablet == 1 & !missing(`a') & !missing(`b')
replace willcons`i' = 2 if `a' <= 2 & `b' > 2 & i_scsmtphone == 1 & i_sctablet == 1 & !missing(`a') & !missing(`b')
replace willcons`i' = 3 if `a' > 2 & `b' <= 2 & i_scsmtphone == 1 & i_sctablet == 1 & !missing(`a') & !missing(`b')
replace willcons`i' = 4 if `a' > 2 & `b' > 2 & i_scsmtphone == 1 & i_sctablet == 1 & !missing(`a') & !missing(`b')
label values willcons`i' willconsl
}

// consistency of willingness, with missing values - consistency variable (Table A3)
foreach x of var willcons* {
	svy: tab `x' if i_scsmtphone == 1 & i_sctablet == 1 , miss
}

// stacked bar chart, without missing values (Figure 4)
keep pidp willcons* i_indscip_xw
reshape long willcons, i(pidp) j(type)
gen will1=willcons==1 if !missing(willcons)
gen will2=willcons==2 if !missing(willcons)
gen will3=willcons==3 if !missing(willcons)
gen will4=willcons==4 if !missing(willcons)

replace will1=will1*100
replace will2=will2*100
replace will3=will3*100
replace will4=will4*100

label define typel 1 "Questionnaire" 2 "Survey app" 3 "Tracking app" 4 "Camera" 5 "Bluetooth", replace
label values type typel
graph hbar (mean) will1 will2 will3 will4 [pweight=i_indscip_xw], over(type) stack legend(col(1) lab(1 "Willing on both devices") lab(2 "Willing on smartphone") lab(3 "Willing on tablet") lab(4 "Not willing on either device") ) ytick(0(10)100) ytitle("Percent") note("Note. Questionnaire, survey app, camera: N = 977. Bluetooth: N = 976." "Tracking app: N = 975.") scheme(s2mono)
/*
Changed colors of bars:
Grayscale 7, Fill intensity: Full, Different outline color: Black
Grayscale 15, Fill intensity: Full, Different outline color: Black
Grayscale 11, Fill intensity: Full, Different outline color: Black
Grayscale 3, Fill intensity: Full, Different outline color: Black
*/


* RESEARCH QUESTION 3

* Note. Re-run code from DATA MANAGEMENT section (lines 31-323).

// bivariate analysis: smartphone

* recode continuous variables as categorical for presentation in table
gen genactspC = 1 if genactsp == 0 | genactsp == 1 | genactsp == 2
replace genactspC = 2 if genactsp == 3 | genactsp == 4
replace genactspC = 3 if genactsp == 5 | genactsp == 6
replace genactspC = 4 if genactsp == 7 | genactsp == 8
replace genactspC = 5 if genactsp == 9 | genactsp == 10
replace genactspC = 6 if genactsp == 11 | genactsp == 12

gen scworryspC = 1 if scworrymeansp < 1.5
replace scworryspC = 2 if scworrymeansp >= 1.5 & scworrymeansp < 2.5
replace scworryspC = 3 if scworrymeansp >= 2.5 & scworrymeansp < 3.5
replace scworryspC = 4 if scworrymeansp >= 3.5 & scworrymeansp < 4.5
replace scworryspC = 5 if scworrymeansp >= 4.5

gen propinterviewC = 0 if propinterview != 1
replace propinterviewC = 1 if propinterview == 1

* create empty matrix
global vars = "dailyusesp genactspC ablesp wifi dataplan timeconstraint physlim scworryspC itemnr linkage eligibleC propinterviewC"

local x = 1
foreach var in $vars {
	capture tab `var'
	local n = r(r)+1
	capture matrix F`x' = J(`n',8,.)
	local x = `x'+1
}
matrix F = F1
forvalues t = 2/`x' {
	capture matrix F = F\F`t'
}
matrix A = F
matrix colnames A = "Camera" "Accelerometer" "Questionnaire" "Bluetooth" "Text messages" "Survey app" "GPS" "Tracking app"

* define program: store tab results in matrix
capture program drop bvs
program define bvs
ereturn clear
local n = 1
foreach var in $vars  {
	capture tab `var'
	local x = r(r)-1
	quietly svy: tab `var' `1'
	matrix freqA = e(total) * e(Prop)
	matrix X1 = J(2,1,1)
	matrix freqSum = freqA * X1
	matrix freqB = freqA, freqSum
	foreach z of numlist 0 1/`x' {
		matrix A[`n'+`z',`2'] = round((freqB[`z'+1,2]/freqB[`z'+1,3])*100, 0.1)
	}
	matrix A[`n'+`x'+1,`2'] = round(e(p_Pear), 0.001)
	local n = `n' + `x' + 2
}
end

* run program
local outcome "will5spdum will6spdum will1spdum will8spdum will4spdum will2spdum will7spdum will3spdum"
forvalues i = 1/8 {
local a : word `i' of `outcome'
bvs `a' `i' 
}

* display matrix (Table A4)
matrix list A

// check that program stores the correct values
foreach var in $vars {
	svy: tab `var' will5spdum, row percent
}

foreach var in $vars {
	svy: tab `var' will6spdum, row percent
}

foreach var in $vars {
	svy: tab `var' will1spdum, row percent
}

foreach var in $vars {
	svy: tab `var' will8spdum, row percent
}

foreach var in $vars {
	svy: tab `var' will4spdum, row percent
}

foreach var in $vars {
	svy: tab `var' will2spdum, row percent
}

foreach var in $vars {
	svy: tab `var' will7spdum, row percent
}

foreach var in $vars {
	svy: tab `var' will3spdum, row percent
}

// bivariate analysis: tablet

* recode continuous variables as categorical for presentation in table
gen genacttbC = 1 if genacttb == 0 | genacttb == 1 | genacttb == 2
replace genacttbC = 2 if genacttb == 3 | genacttb == 4
replace genacttbC = 3 if genacttb == 5 | genacttb == 6
replace genacttbC = 4 if genacttb == 7 | genacttb == 8
replace genacttbC = 5 if genacttb == 9 | genacttb == 10
replace genacttbC = 6 if genacttb == 11 | genacttb == 12

* create empty matrix
global vars = "dailyusetb genacttbC abletb wifi timeconstraint physlim scworryspC itemnr linkage eligibleC propinterviewC"
local x = 1
foreach var in $vars {
	capture tab `var'
	local n = r(r)+1
	capture matrix G`x' = J(`n',5,.)
	local x = `x'+1
}
matrix G = G1
forvalues t = 2/`x' {
	capture matrix G = G\G`t'
}
matrix B = G
matrix colnames B = "Questionnaire" "Survey app" "Camera" "Bluetooth" "Tracking app"

* define program: store tab results in matrix
capture program drop bvs
program define bvs
ereturn clear
local n = 1
foreach var in $vars  {
	capture tab `var'
	local x = r(r)-1
	quietly svy: tab `var' `1'
	matrix freqA = e(total) * e(Prop)
	matrix X1 = J(2,1,1)
	matrix freqSum = freqA * X1
	matrix freqB = freqA, freqSum
	foreach z of numlist 0 1/`x' {
		matrix B[`n'+`z',`2'] = round((freqB[`z'+1,2]/freqB[`z'+1,3])*100, 0.1)
	}
	matrix B[`n'+`x'+1,`2'] = round(e(p_Pear), 0.001)
	local n = `n' + `x' + 2
}
end

// collapse strata with single PSUs
gen newstr = i_strata
gen newpsu = i_psu
replace newpsu = i_psu + 57 if i_strata == 56
replace newstr = 57 if i_strata == 56

// declare sample design with collapsed strata
svyset, clear
svyset newpsu [pweight=i_indscip_xw], strata(newstr)

* run program
local outcome "will1tbdum will2tbdum  will5tbdum will8tbdum will3tbdum"
forvalues i = 1/5 {
local a : word `i' of `outcome'
bvs `a' `i' 
}
matrix list B

// check that program stores the correct values
foreach var in $vars {
	svy: tab `var' will1tbdum, row percent
}

foreach var in $vars {
	svy: tab `var' will2tbdum, row percent
}

foreach var in $vars {
	svy: tab `var' will5tbdum, row percent
}

foreach var in $vars {
	svy: tab `var' will8tbdum, row percent
}

foreach var in $vars {
	svy: tab `var' will3tbdum, row percent
}

// check association of age and willingness
* compute mean willingness across tasks
egen willspmean = rowmean(will1sp will2sp will3sp will4sp will5sp will6sp will7sp will8sp)
egen willtbmean = rowmean(will1tb will2tb will3tb will5tb will8tb)

* recode into age groups
gen agegp = 1 if age < 20 & !missing(age)
replace agegp = 2 if age >= 20 & age < 30 & !missing(age)
replace agegp = 3 if age >= 30 & age < 40 & !missing(age)
replace agegp = 4 if age >= 40 & age < 50 & !missing(age)
replace agegp = 5 if age >= 50 & age < 60 & !missing(age)
replace agegp = 6 if age >= 60 & age < 70 & !missing(age)
replace agegp = 7 if age >= 70 & age < 80 & !missing(age)
replace agegp = 8 if age >= 80 & age < 90 & !missing(age)
replace agegp = 9 if age >= 90 & age < 100 & !missing(age)

* compute mean willignness per age group
bysort agegp: egen willspmean_byagegp = mean(willspmean)
bysort agegp: egen willtbmean_byagegp = mean(willtbmean)

* scatter plot: mean willingness by age group
twoway scatter willspmean_byagegp agegp
twoway scatter willtbmean_byagegp agegp

// check income distribution
sum inc, d
hist inc
hist incln

// multivariate analysis: smartphone

* -- ordered logistic regression
local willsp "will5sp will6sp will1sp will8sp will4sp will2sp will7sp will3sp"
forvalues i = 1/8 {
local a: word `i' of `willsp'
svy: ologit `a' dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview b3.eligibleC female age age2 b4.edu empl incln owned
margins, dydx(*) post
estimates store m`i'
}
estout m* using I:\Alex_Annette_Mick\output\ologit_smartphone.doc, replace margin cells(b(star fmt(3)) se(par fmt(2))) stats(N, fmt(3 0))

* -- binary logistic regression (Table 3)
local willspdum "will5spdum will6spdum will1spdum will8spdum will4spdum will2spdum will7spdum will3spdum"
forvalues i = 1/8 {
local a: word `i' of `willspdum'
svy: logit `a' dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview b3.eligibleC female age age2 b4.edu empl incln owned
margins, dydx(*) post
estimates store m`i'
}
estout m* using I:\Alex_Annette_Mick\output\blogit_smartphone.doc, replace margin cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0))

// create table of p-values to account for multiple testing using the Holm-Bonferroni method
estout m* using I:\Alex_Annette_Mick\output\blogit_smartphone_pval.doc, replace margin cells(p(fmt(21)))

// check that p-values are from average marginal effects (example: camera)
svy: logit will5spdum dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview b3.eligibleC female age age2 b4.edu empl incln owned
margins, dydx(*) post

// compute goodness-of-fit statistics 
local willspdum "will5spdum will6spdum will1spdum will8spdum will4spdum will2spdum will7spdum will3spdum"
forvalues i = 1/8 {
local a: word `i' of `willspdum'
logit `a' dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web b3.eligibleC propinterview female age age2 b4.edu empl incln owned [pweight=i_indscip_xw], cluster(i_psu)
fitstat
}

// binary logistic regression, including interaction between number of eligible waves and prior panel response rate
local willspdum "will5spdum will6spdum will1spdum will8spdum will4spdum will2spdum will7spdum will3spdum"
forvalues i = 1/8 {
local a: word `i' of `willspdum'
svy: logit `a' dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web b3.eligibleC##c.propinterview female age age2 b4.edu empl incln owned
margins, dydx(*) post
}

// test equality of coefficients across models
local willspdum "will5spdum will6spdum will1spdum will8spdum will4spdum will2spdum will7spdum will3spdum"
forvalues i = 1/8 {
local a: word `i' of `willspdum'
svy: logit `a' dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview b3.eligibleC female age age2 b4.edu empl incln owned
estimates store m`i'
}
suest m1 m2 m3 m4 m5 m6 m7 m8, svy
test[#7=#8]: scworrymeansp
test[#7=#5]: scworrymeansp

test[#1=#2]: genactsp
test[#3=#4]: genactsp

svy: logit will5spdum dailyusesp
estimates store m1
svy: logit will6spdum dailyusesp
estimates store m2
suest m1 m2
test[#1=#2]: dailyusesp


// multivariate analysis: tablet

* -- ordered logistic regression
local willtb "will1tb will2tb will5tb will8tb will3tb"
forvalues i = 1/5 {
local a: word `i' of `willtb'
svy: ologit `a' dailyusetb genacttb abletb physlim wifi timeconstraint scworrymeansp itemnr linkage web propinterview b3.eligibleC female age age2 b4.edu empl incln owned
margins, dydx(*) post
estimates store m`i'
}
estout m1 m2 m3 m4 m5 using I:\Alex_Annette_Mick\output\ologit_tablet.doc, replace margin cells(b(star fmt(3)) se(par fmt(2))) stats(N, fmt(3 0))

* -- binary logistic regression
local willtb "will1tbdum will2tbdum will5tbdum will8tbdum will3tbdum"
forvalues i = 1/5 {
local a: word `i' of `willtb'
svy: logit `a' dailyusetb genacttb abletb physlim wifi timeconstraint scworrymeansp itemnr linkage web propinterview b3.eligibleC female age age2 b4.edu empl incln owned
margins, dydx(*) post
estimates store m`i'
}
estout m1 m2 m3 m4 m5 using I:\Alex_Annette_Mick\output\blogit_tablet.doc, replace margin cells(b(star fmt(3)) se(par fmt(2))) stats(N, fmt(3 0))


* RESEARCH QUESTION 4

* Note. Re-run code from DATA MANAGEMENT section (lines 31-323).

// reshape dataset to long format
keep pidp i_psu i_strata i_indscip_xw i_scwill*sp dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC female age age2 edu empl incln owned
rename (i_scwill*sp) (i_scwill*)
reshape long i_scwill, i(pidp) j(task)
label var task "Data collection task"
label define taskl 1 "Questionnaire" 2 "Survey app" 3 "Tracking app" 4 "SMS survey" 5 "Camera" 6 "Accelerometer" 7 "GPS" 8 "Bluetooth", replace
label values task taskl

// dichotomise willingness variable
gen will = abs(i_scwill-5)
label var will "Willingness"
gen willdum = 1 if will == 3 | will == 4
replace willdum = 0 if will == 1 | will == 2
label var willdum "Willingness"

// code task characteristics
gen app = 1 if task == 2 | task == 3 | task >= 5
replace app = 0 if task == 1 | task == 4
label var app "Requires downloading and installing an app"

gen active = 1 if task <= 2 | task == 4 | task == 5
replace active = 0 if task == 3 | task >= 6
label var active "Active role of respondent"

gen techdem = 1 if task == 3 | task >= 5
replace techdem = 0 if task <= 2 | task == 4
label var techdem "High technical demands"

gen privacy = 1 if task == 3 | task == 7
replace privacy = 0 if task <= 2 | task == 4 | task == 5 | task == 6 | task == 8
label var privacy "Potential privacy threat"

// recode tasks into dummy variables
local taskdummies "survapp trackingapp smssurvey camera accelerometer gps bluetooth"
forvalues i = 1/7 {
	local a: word `i' of `taskdummies'
	local n = `i' + 1
	gen `a' = 0
	replace `a' = 1 if task == `n'
}
label var survapp "Survey app vs. Questionnaire"
label var trackingapp "Tracking app vs. Questionnaire"
label var smssurvey "SMS Survey vs. Questionnaire"
label var camera "Camera vs. Questionnaire"
label var accelerometer "Accelerometer vs. Questionnaire"
label var gps "GPS vs. Questionnaire"
label var bluetooth "Bluetooth vs. Questionnaire"

// compute weight for each level
gen indscip1 = 1
gen indscip2 = i_indscip_xw

// recode categorical variables into dummy variables
gen eligibleC1 = 1 if eligibleC == 1
replace eligibleC1 = 0 if eligibleC == 2 | eligibleC == 3

gen eligibleC2 = 1 if eligibleC == 2
replace eligibleC2 = 0 if eligibleC == 1 | eligibleC == 3

gen edu1 = 1 if edu == 1
replace edu1 = 0 if edu > 1

gen edu2 = 1 if edu == 2
replace edu2 = 0 if edu == 1 | edu > 2

gen edu3 = 1 if edu == 3
replace edu3 = 0 if edu == 1 | edu == 2 | edu == 4

// multilevel logistic regression: smartphone (Table 4)
* -- Model 3: task and respondent characteristics
gllamm willdum app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
matrix a=e(b) 
local n=colsof(a)
matrix a[1,`n']=ln(a[1,`n'])
xtlogit willdum app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned, re i(pidp) from(a,copy) intpoints(30) iterate(0) 
estimates store lr2
di e(sigma_u)^2 // respondent variance
di e(rho) // intra-class correlation
estat ic // model fit statistics
margins, dydx(*) post
estimates store m2
gen sample = e(sample)

* willingness to participate in mobile data collection across tasks
svy: tab willdum if sample == 1

* -- Model 2: task characteristics
gllamm willdum app active techdem privacy if sample == 1, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
matrix a=e(b) 
local n=colsof(a)
matrix a[1,`n']=ln(a[1,`n'])
xtlogit willdum app active techdem privacy if sample == 1, re i(pidp) from(a,copy) intpoints(30) iterate(0) 
estimates store lr1
di e(sigma_u)^2 // respondent variance
di e(rho) // intra-class correlation
estat ic // model fit statistics
margins, dydx(*) post
estimates store m1

lrtest lr1 lr2 // LR test: Model 1 vs. Model 2

* -- Model 1: null model
gllamm willdum if sample == 1, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
matrix a=e(b) 
local n=colsof(a)
matrix a[1,`n']=ln(a[1,`n'])
xtlogit willdum if sample == 1, re i(pidp) from(a,copy) intpoints(30) iterate(0)
estimates store lr0
di e(sigma_u)^2 // respondent variance
di e(rho) // intra-class correlation
estat ic // model fit statistics 

lrtest lr0 lr1 // LR test: Model 0 vs. Model 1

estout m1 m2 using I:\Alex_Annette_Mick\output\mllogit_smartphone.doc, replace margin cells(b(star fmt(3)) se(fmt(3))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label

// multilevel logistic regression: smartphone, including dummies for individual tasks instead of task characteristics
* -- Model 3: task dummies and respondent characteristics
gllamm willdum survapp trackingapp smssurvey camera accelerometer gps bluetooth dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
matrix a=e(b) 
local n=colsof(a)
matrix a[1,`n']=ln(a[1,`n'])
xtlogit willdum survapp trackingapp smssurvey camera accelerometer gps bluetooth dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned, re i(pidp) from(a,copy) intpoints(30) iterate(0) 
estimates store lr2
di e(sigma_u)^2 // respondent variance
di e(rho) // intra-class correlation
estat ic // model fit statistics
gen sample = e(sample)

* -- Model 2: task dummies
gllamm willdum survapp trackingapp smssurvey camera accelerometer gps bluetooth if sample == 1, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
matrix a=e(b) 
local n=colsof(a)
matrix a[1,`n']=ln(a[1,`n'])
xtlogit willdum survapp trackingapp smssurvey camera accelerometer gps bluetooth if sample == 1, re i(pidp) from(a,copy) intpoints(30) iterate(0) 
estimates store lr1
di e(sigma_u)^2 // respondent variance
di e(rho) // intra-class correlation
estat ic // model fit statistics

lrtest lr1 lr2 // LR test: Model 1 vs. Model 2

* -- Model 1: null model
gllamm willdum if sample == 1, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
matrix a=e(b) 
local n=colsof(a)
matrix a[1,`n']=ln(a[1,`n'])
xtlogit willdum if sample == 1, re i(pidp) from(a,copy) intpoints(30) iterate(0)
estimates store lr0
di e(sigma_u)^2 // respondent variance
di e(rho) // intra-class correlation
estat ic // model fit statistics 

lrtest lr0 lr1 // LR test: Model 0 vs. Model 1

// multilevel logistic regression: smartphone, including interaction effects

* compute interaction terms
global vars = "dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage propinterview eligibleC1 eligibleC2"
foreach var in $vars {
	gen appX`var' = app * `var'
	gen activeX`var' = active * `var'
	gen techdemX`var' = techdem * `var'
	gen privacyX`var' = privacy * `var'
}

global socdem = "female age edu1 edu2 edu3 empl incln owned"
foreach var in $socdem {
	gen appX`var' = app * `var'
	gen activeX`var' = active * `var'
	gen techdemX`var' = techdem * `var'
	gen privacyX`var' = privacy * `var'
}

* test interaction: app requirement X respondent characteristics
set more off
global indvars = "app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned"
local interaction "appXdailyusesp appXgenactsp appXablesp appXphyslim appXwifi appXdataplan appXtimeconstraint appXscworrymeansp appXitemnr appXlinkage appXpropinterview"
forvalues i = 1/11 {
	local a: word `i' of `interaction'
	gllamm willdum $indvars `a', i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
	estimates store m1`i'
}
gllamm willdum $indvars appXeligibleC1 appXeligibleC2, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
estimates store m112

estout m11 m12 m13 m14 m15 m16 m17 m18 m19 m110 m111 m112 using I:\Alex_Annette_Mick\output\appX_pval_smartphone.doc, replace cells(p(fmt(25)))
estout m11 m12 m13 m14 m15 m16 m17 m18 m19 m110 m111 m112 using I:\Alex_Annette_Mick\output\appX_b_smartphone.doc, replace cells(b(star fmt(8)) se(fmt(8))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label

* test interaction: active role of respondent X respondent characteristics
set more off
global indvars = "app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned"
local interaction "activeXdailyusesp activeXgenactsp activeXablesp activeXphyslim activeXtimeconstraint activeXscworrymeansp activeXitemnr activeXlinkage activeXpropinterview"
forvalues i = 1/9 {
	local a: word `i' of `interaction'
	gllamm willdum $indvars `a', i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
	estimates store m2`i'
}
gllamm willdum $indvars activeXeligibleC1 activeXeligibleC2, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
estimates store m210

estout m21 m22 m23 m24 m25 m26 m27 m28 m29 m210 using I:\Alex_Annette_Mick\output\activeX_pval_smartphone.doc, replace cells(p(fmt(25)))
estout m21 m22 m23 m24 m25 m26 m27 m28 m29 m210 using I:\Alex_Annette_Mick\output\activeX_b_smartphone.doc, replace cells(b(star fmt(8)) se(fmt(8))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label

* test interaction: high technical demands X respondent characteristics
set more off
global indvars = "app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned"
local interaction "techdemXwifi techdemXdataplan techdemXscworrymeansp techdemXitemnr techdemXlinkage techdemXpropinterview"
forvalues i = 1/6 {
	local a: word `i' of `interaction'
	gllamm willdum $indvars `a', i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
	estimates store m3`i'
}
gllamm willdum $indvars techdemXeligibleC1 techdemXeligibleC2, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
estimates store m37

estout m31 m32 m33 m34 m35 m36 m37 using I:\Alex_Annette_Mick\output\techdemX_pval_smartphone.doc, replace cells(p(fmt(25)))
estout m31 m32 m33 m34 m35 m36 m37 using I:\Alex_Annette_Mick\output\techdemX_b_smartphone.doc, replace cells(b(star fmt(8)) se(fmt(8))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label

* test interaction: potential privacy threat X respondent characteristics
set more off
global indvars = "app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned"
local interaction "privacyXscworrymeansp privacyXitemnr privacyXlinkage privacyXpropinterview"
forvalues i = 1/4 {
	local a: word `i' of `interaction'
	gllamm willdum $indvars `a', i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
	estimates store m4`i'
}
gllamm willdum $indvars privacyXeligibleC1 privacyXeligibleC2, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
estimates store m45

estout m41 m42 m43 m44 m45 using I:\Alex_Annette_Mick\output\privacyX_pval_smartphone.doc, replace cells(p(fmt(25)))
estout m41 m42 m43 m44 m45 using I:\Alex_Annette_Mick\output\privacyX_b_smartphone.doc, replace cells(b(star fmt(8)) se(fmt(8))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label

* compute average marginal effects for significant interaction terms
set more off
global indvars = "app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned"
local interaction "appXdailyusesp activeXdailyusesp activeXpropinterview techdemXpropinterview privacyXpropinterview"
forvalues i = 1/5 {
	local x: word `i' of `interaction'
	gllamm willdum $indvars `x' if sample == 1, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
	matrix a=e(b)
	local n=colsof(a)
	matrix a[1, `n']=ln(a[1, `n'])
	xtlogit willdum $indvars `x' if sample == 1, re i(pidp) from(a, copy) intpoints(30) iterate(0)
	margins, dydx(*) post
	estimates store m5`i'
}

estout m51 m52 m53 m54 m55 using I:\Alex_Annette_Mick\output\sigX_ame_smartphone.doc, replace margin cells(b(star fmt(3)) se(fmt(3))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label
estout m51 m52 m53 m54 m55 using I:\Alex_Annette_Mick\output\sigX_pval_smartphone.doc, replace margin cells(p(star fmt(3))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label

* test interaction: task characteristics X socio-demographics
* -- app requirement
set more off
global indvars = "app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned"
local interaction "appXfemale appXage appXempl appXincln appXowned"
forvalues i = 1/5 {
	local a: word `i' of `interaction'
	gllamm willdum $indvars `a', i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
	estimates store m6`i'
}
gllamm willdum $indvars appXedu1 appXedu2 appXedu3, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
estimates store m66

estout m61 m62 m63 m64 m65 m66 using I:\Alex_Annette_Mick\output\appXsocdem_pval_smartphone.doc, replace cells(p(fmt(25)))
estout m61 m62 m63 m64 m65 m66 using I:\Alex_Annette_Mick\output\appXsocdem_b_smartphone.doc, replace cells(b(star fmt(8)) se(fmt(8))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label

* -- active role of respondent
set more off
global indvars = "app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned"
local interaction "activeXfemale activeXage activeXempl activeXincln activeXowned"
forvalues i = 1/5 {
	local a: word `i' of `interaction'
	gllamm willdum $indvars `a', i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
	estimates store m7`i'
}
gllamm willdum $indvars activeXedu1 activeXedu2 activeXedu3, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
estimates store m76

estout m71 m72 m73 m74 m75 m76 using I:\Alex_Annette_Mick\output\activeXsocdem_pval_smartphone.doc, replace cells(p(fmt(25)))
estout m71 m72 m73 m74 m75 m76 using I:\Alex_Annette_Mick\output\activeXsocdem_b_smartphone.doc, replace cells(b(star fmt(8)) se(fmt(8))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label

* -- high technical demands
set more off
global indvars = "app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned"
local interaction "techdemXfemale techdemXage techdemXempl techdemXincln techdemXowned"
forvalues i = 1/5 {
	local a: word `i' of `interaction'
	gllamm willdum $indvars `a', i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
	estimates store m8`i'
}
gllamm willdum $indvars techdemXedu1 techdemXedu2 techdemXedu3, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
estimates store m86

estout m81 m82 m83 m84 m85 m86 using I:\Alex_Annette_Mick\output\techdemXsocdem_pval_smartphone.doc, replace cells(p(fmt(25)))
estout m81 m82 m83 m84 m85 m86 using I:\Alex_Annette_Mick\output\techdemXsocdem_b_smartphone.doc, replace cells(b(star fmt(8)) se(fmt(8))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label

* -- potential privacy threat
set more off
global indvars = "app active techdem privacy dailyusesp genactsp ablesp physlim wifi dataplan timeconstraint scworrymeansp itemnr linkage web propinterview eligibleC1 eligibleC2 female age age2 edu1 edu2 edu3 empl incln owned"
local interaction "privacyXfemale privacyXage privacyXempl privacyXincln privacyXowned"
forvalues i = 1/5 {
	local a: word `i' of `interaction'
	gllamm willdum $indvars `a', i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
	estimates store m9`i'
}
gllamm willdum $indvars privacyXedu1 privacyXedu2 privacyXedu3, i(pidp) pweight(indscip) family(binomial) link(logit) cluster(i_psu) dots
estimates store m96

estout m91 m92 m93 m94 m95 m96 using I:\Alex_Annette_Mick\output\privacyXsocdem_pval_smartphone.doc, replace cells(p(fmt(25)))
estout m91 m92 m93 m94 m95 m96 using I:\Alex_Annette_Mick\output\privacyXsocdem_b_smartphone.doc, replace cells(b(star fmt(8)) se(fmt(8))) stats(sigma_u sigma_e rho N, fmt(3 3 3 0)) label

