One huge disadvantage of NetQuestionnaire (NetQ) is that randomisation is only possible for the order of sub-items of questions. There is, however, a way to use Stata to make anything random (e.g. the order of questions, content of questions). Below, I describe a way how to generate randomly sets of vignettes. At the end of the do-file, text is saved to an Excel-file). Merged with an address-list, this information can be imported to NetQ, and used in questions using the NetQ-variables.
Note that the do-file can easily be adjusted in order to be used for other purposes.
The do-file describes the randomisation for 6 pairs of vignettes. Respondents may choose vignette A or vignette B, where A and B is a set of certain characteristics (in the example below, there are 5 characterisics: city, venue, dinner, social event, speaker).
We randomise the order of characteristics (each person receives the characteristics in a specific order), and the content of the vignettes.
*-----------------------------*
* Do-file for Vignettes
* (Jan Sauermann, November 2008)
clear
drop _all
matrix drop _all
set mem 100m
set more off
* ———————————————-
* Idea
* ———————————————-
* what do we need:
* – generate random variables for each field in each vignette
* i.e. 6 different vignettes (“vignettepair”)
* 2 vignettes per page (“pair”)
* 6 dimensions (city, etc.)
* –> 72 variables
* names of one pair of vignettes
* 11a 11b
* – first number denotes the number of the vignette (1-6)
* – second number denotes vignette left or right
* – third number denotes dimension
* – a = city (6: Oxford; Barcelona; Budapest; Uppsala; Frankfurt; Malta)
* – b = venue (2: Hotel, University)
* – c = period (4: May, June, September, October)
* – d = speaker (4: 1 speaker (nobel laureate); 2 speakers (incl. 1 nobel laureate); 1 speaker; 2 speakers)
* – e = social event (3: Formal dinner; Informal Garden BBQ; Reception City Hall)
* ———————————————-
* Randomly generate vignettes
* ———————————————-
set seed 1
* set number of addresses
local cases = 1500
* set number of max. generated pairs
local maxobs = `cases’ * 10
* for each pair of variable (e.g.: city in vignette 1 (a) vs. city in vignette 1 (b)) create a separate dataset with ONLY different answering options. Merge these separate datafiles by adding a rank.
* run the loop for all 5 dimensions (local options will store num. of options)
local dimension = “a b c d e”
foreach dim of local dimension {
foreach vignettepair of numlist 1/6 {
* set maximum number of observations
set obs `maxobs’
* set number of different options (depending on dimension)
if “`dim’” == “a” {
local options = 6
}
if “`dim’” == “b” {
local options = 2
}
if “`dim’” == “c” {
local options = 4
}
if “`dim’” == “d” {
local options = 4
}
if “`dim’” == “e” {
local options = 3
}
* randomly generate pairs and drop equal pairs
foreach pair of numlist 1/2 {
gen var`vignettepair’`pair’`dim’ = int(1 + (`options’)*uniform())
}
drop if var`vignettepair’1`dim’ == var`vignettepair’2`dim’
* generate rank, limit the sample and sort
gen rank = _n
drop if rank > `cases’
sort rank
* save temporary file
save vign`vignettepair’`dim’, replace
clear
* merge the separate files to the first (–> for each dimension, one subfile)
if `vignettepair’ == 1 {
use vign`vignettepair’`dim’
save vign_`dim’, replace
erase vign`vignettepair’`dim’.dta
clear
}
if `vignettepair’ > 1 {
use vign_`dim’
merge rank using vign`vignettepair’`dim’, _merge(merge`vignettepair’`dim’)
sort rank
save vign_`dim’, replace
erase vign`vignettepair’`dim’.dta
clear
}
}
* merge the subfiles to one file called vignettes.dta
if “`dim’” == “a” {
use vign_`dim’, clear
sort rank
save vignettes, replace
clear
erase vign_`dim’.dta
}
if “`dim’” == “b” | “`dim’” == “c” | “`dim’” == “d” | “`dim’” == “e” {
use vignettes, clear
merge rank using vign_`dim’, _merge(merge`dim’)
sort rank
save vignettes, replace
erase vign_`dim’.dta
clear
}
}
* if all merge* variables only have values of 3, all dta’s have sufficient number of observations
use vignettes, clear
tab1 merge*
drop merge*
* ———————————————-
* Translate numbers to text
* ———————————————-
foreach vignettepair of numlist 1/6 {
foreach leftright of numlist 1/2 {
* generate city variables
gen var`vignettepair’`leftright’a_text = “”
replace var`vignettepair’`leftright’a_text = “Oxford” if var`vignettepair’`leftright’a == 1
replace var`vignettepair’`leftright’a_text = “Barcelona” if var`vignettepair’`leftright’a == 2
replace var`vignettepair’`leftright’a_text = “Budapest” if var`vignettepair’`leftright’a == 3
replace var`vignettepair’`leftright’a_text = “Uppsala” if var`vignettepair’`leftright’a == 4
replace var`vignettepair’`leftright’a_text = “Frankfurt” if var`vignettepair’`leftright’a == 5
replace var`vignettepair’`leftright’a_text = “Malta” if var`vignettepair’`leftright’a == 6
* generate venue variables
gen var`vignettepair’`leftright’b_text = “”
replace var`vignettepair’`leftright’b_text = “Hotel” if var`vignettepair’`leftright’b == 1
replace var`vignettepair’`leftright’b_text = “University” if var`vignettepair’`leftright’b == 2
* generate period variables
gen var`vignettepair’`leftright’c_text = “”
replace var`vignettepair’`leftright’c_text = “May” if var`vignettepair’`leftright’c == 1
replace var`vignettepair’`leftright’c_text = “June” if var`vignettepair’`leftright’c == 2
replace var`vignettepair’`leftright’c_text = “September” if var`vignettepair’`leftright’c == 3
replace var`vignettepair’`leftright’c_text = “October” if var`vignettepair’`leftright’c == 4
* generate speaker variables
gen var`vignettepair’`leftright’d_text = “”
replace var`vignettepair’`leftright’d_text = “1 speaker (nobel laureate)” if var`vignettepair’`leftright’d == 1
replace var`vignettepair’`leftright’d_text = “2 speakers (incl. 1 nobel laureate)” if var`vignettepair’`leftright’d == 2
replace var`vignettepair’`leftright’d_text = “1 speaker” if var`vignettepair’`leftright’d == 3
replace var`vignettepair’`leftright’d_text = “2 speakers” if var`vignettepair’`leftright’d == 4
* generate social even variables
gen var`vignettepair’`leftright’e_text = “”
replace var`vignettepair’`leftright’e_text = “Formal dinner” if var`vignettepair’`leftright’e == 1
replace var`vignettepair’`leftright’e_text = “Informal Garden BBQ” if var`vignettepair’`leftright’e == 2
replace var`vignettepair’`leftright’e_text = “Reception City Hall” if var`vignettepair’`leftright’e == 3
}
}
* ———————————————-
* Generate random order of dimensions
* ———————————————-
* idea: for each person, generate an order of dimensions (fixed for i)
* procedure:
* – generate random variable for each dimension (different for each individual)
* – find the lowest value and set it to 101
* – repeat this step, set it to 102
* – etc.
* – finally, substract 100
* –> Rank
local dimensions = “a b c d e”
foreach dim of local dimensions{
gen help_`dim’ = uniform()
}
egen help = rowmin(help_a help_b help_c help_d help_e)
foreach dim of local dimensions{
replace help_`dim’ = 101 if help == help_`dim’
}
drop help
egen help = rowmin(help_a help_b help_c help_d help_e)
foreach dim of local dimensions{
replace help_`dim’ = 102 if help == help_`dim’
}
drop help
egen help = rowmin(help_a help_b help_c help_d help_e)
foreach dim of local dimensions{
replace help_`dim’ = 103 if help == help_`dim’
}
drop help
egen help = rowmin(help_a help_b help_c help_d help_e)
foreach dim of local dimensions{
replace help_`dim’ = 104 if help == help_`dim’
}
drop help
egen help = rowmin(help_a help_b help_c help_d help_e)
foreach dim of local dimensions{
replace help_`dim’ = 105 if help == help_`dim’
}
drop help
* rescale to 1-5 (1 being the first to be presented)
foreach dim of local dimensions{
rename help_`dim’ rank_`dim’
replace rank_`dim’ = rank_`dim’ – 100
}
* ———————————————-
* Resort the entries (based on the random ranking)
* ———————————————-
local dimensions = “a b c d e”
foreach vignettepair of numlist 1/6 {
foreach leftright of numlist 1/2 {
foreach dim of local dimensions {
gen var`vignettepair’`leftright’`dim’_unranked = var`vignettepair’`leftright’`dim’
gen var`vignettepair’`leftright’`dim’_text_unranked = var`vignettepair’`leftright’`dim’_text
}
}
}
foreach vignettepair of numlist 1/6 {
foreach leftright of numlist 1/2 {
foreach dim of local dimensions {
replace var`vignettepair’`leftright’a = var`vignettepair’`leftright’`dim’_unranked if rank_`dim’ == 1
replace var`vignettepair’`leftright’b = var`vignettepair’`leftright’`dim’_unranked if rank_`dim’ == 2
replace var`vignettepair’`leftright’c = var`vignettepair’`leftright’`dim’_unranked if rank_`dim’ == 3
replace var`vignettepair’`leftright’d = var`vignettepair’`leftright’`dim’_unranked if rank_`dim’ == 4
replace var`vignettepair’`leftright’e = var`vignettepair’`leftright’`dim’_unranked if rank_`dim’ == 5
replace var`vignettepair’`leftright’a_text = var`vignettepair’`leftright’`dim’_text_unranked if rank_`dim’ == 1
replace var`vignettepair’`leftright’b_text = var`vignettepair’`leftright’`dim’_text_unranked if rank_`dim’ == 2
replace var`vignettepair’`leftright’c_text = var`vignettepair’`leftright’`dim’_text_unranked if rank_`dim’ == 3
replace var`vignettepair’`leftright’d_text = var`vignettepair’`leftright’`dim’_text_unranked if rank_`dim’ == 4
replace var`vignettepair’`leftright’e_text = var`vignettepair’`leftright’`dim’_text_unranked if rank_`dim’ == 5
}
}
}
* applying NetQ names
foreach vignettepair of numlist 1/6 {
foreach leftright of numlist 1/2 {
foreach dim of local dimensions {
rename var`vignettepair’`leftright’`dim’_text nqopt`vignettepair’`leftright’`dim’
}
}
}
* adding dimension names (for each person only once)
local dimension_a = “city”
local dimension_b = “venue”
local dimension_c = “period”
local dimension_d = “speaker”
local dimension_e = “social event”
foreach dim of local dimensions {
gen nqdim`dim’ = “”
}
foreach dim of local dimensions {
replace nqdima = “`dimension_`dim”” if rank_`dim’ == 1
replace nqdimb = “`dimension_`dim”” if rank_`dim’ == 2
replace nqdimc = “`dimension_`dim”” if rank_`dim’ == 3
replace nqdimd = “`dimension_`dim”” if rank_`dim’ == 4
replace nqdime = “`dimension_`dim”” if rank_`dim’ == 5
}
* ———————————————-
* Optional: Generate a lottery number
* ———————————————-
* generate random number; sort by this random number; generate rank (1-N)
* –> “1” wins
gen double random = uniform()
sort random
gen nqlotterij = _n
drop random
sort rank
* ———————————————-
* Saving and exporting
* ———————————————-
* for better use in netQ
rename rank nqid
aorder nqid email
* save full file (for reference purposes)
compress
save vignettes_full, replace
xmlsave vignettes_full, doctype(excel) replace
* save restricted file for import to NetQ
keep nq* email
save vignettes_netqimport, replace
xmlsave vignettes_netqimport, doctype(excel) replace
exit
*-----------------------------*
Leave a Reply
You must be logged in to post a comment.