Ok, i'm not getting anywhere with panelrecords function.
Problem 1:
here are the elements:
IV06_01 - percentages of correct answers on tests of fluid abilities
IV06_02 - percentages of correct answers on tests of crystalized abilities
IV06_03 - percentages of correct answers on tests of visual abilities
feedback text elements (i gave up on placehoders):
DB06 - if crystalized is their strongest side
DB07 - if fluid is their strongest side
DB08 - if visual is their strongest side
I tried chatgpt and this is the code it provided me with:
// load values from database
$fluid = value('IV06_01');
$crystalized = value('IV06_02');
$visual = value('IV06_03');
// make an array
$a = [
'fluid' => $fluid,
'crystalized' => $crystalized,
'visual' => $visual
];
// Find the largest value
$largest = array_keys($a, max($a))[0];
// give feedback
if ($largest == 'fluid') {
text('DB07');
}
elseif ($largest == 'crystalized') {
text('DB06');
}
elseif ($largest == 'visual') {
text('DB08');
}
however, it always gives the same feedback - that fluid is their strongest ability (i checked database, this was not correct, as in some trials participants' had largest score (percentage of correct answers) in crystalized or visual abilities.
Can you provide me with the correct code for this, please?
problem 2:
this is a selfrecruited participants multiwave study:
opt-in
qnr1 (mathematical tasks with scores put in database as internal variables IV03_12 and IV03_13)
qnr2 (intuitive reasoning tasks: IV03_08)
qnr2 (intuitive reasoning tasks 2: IV03_10, and feedback with placehoders)
since i didn't have success on my own chatgpt gave me this code, but the code only returns value for IV03_10 which is the value that is put to database during this current questionnaire, the same one where i provide feedback)
the code is:
// identify current respondent
$case = caseSerial();
// load IV03_08 from qnr2
$pd_qnr2 = panelData($case, array('IV03_08'), 'qnr2');
// load IV03_12 and IV03_13 from qnr1
$pd_qnr1 = panelData($case, array('IV03_12','IV03_13'), 'qnr1');
// read IV03_10 from the current questionnaire
$IV03_10 = value('IV03_10', 'text');
// safe extraction (use array_key_exists so a stored 0 is preserved)
// if the key exists we keep its value (including 0), otherwise set to empty string
if (is_array($pd_qnr2) && array_key_exists('IV03_08', $pd_qnr2)) {
$iv03_08 = $pd_qnr2['IV03_08'];
} else {
$iv03_08 = '';
}
if (is_array($pd_qnr1) && array_key_exists('IV03_12', $pd_qnr1)) {
$iv03_12 = $pd_qnr1['IV03_12'];
} else {
$iv03_12 = '';
}
if (is_array($pd_qnr1) && array_key_exists('IV03_13', $pd_qnr1)) {
$iv03_13 = $pd_qnr1['IV03_13'];
} else {
$iv03_13 = '';
}
// put into placeholders (these placeholders must exist in your text/html)
replace('%placeholderCRTi%', $IV03_08); // IV03_08 from qnr2
replace('%placeholderCRTd%', $IV03_10); // IV03_10 from current qnr - qnr3
replace('%placeholderMW1%', $IV03_12); // IV03_12 from qnr1
replace('%placeholderMW2%', $IV03_13); // IV03_13 from qnr1
so, when i run through all questionnaires and get to the feedback (qnr3) i get the feedback with a number of correctly solved intuitive reasoning tasks only from the current questionnaire ('%placeholderCRTd%', $iv03_10), while the rest of the placeholders appear as empty spaces, no numbers and also no plceholder (so im guessing that sosci calls up a placeholder, but it doesnt read the value assigned to it).
Can you please provide mw with the correct code for this too?
Thank you indefinitely!
Best