Hello,
I have recently come across a challenge when trying to code a model and was hoping someone where had some ideas (apologies in advance if the solution is obvious and I’m just not seeing it, GAMs can be confusing for me sometimes), here’s what I want to do:
*step1. generate a household set
set hh /hh1 hh2 hh3/;
*step2. generate a matching set of double-dash parameters
set dd /dd1 dd2 dd3/;
*step3. make dd1,dd2 and dd3 double dash parameters :
$if not set dd1 $set dd1 0
$if not set dd2 $set dd2 0
$if not set dd3 $set dd3 0
*(I need this step to be in a loop, I have tried:
loop(dd,
$if not set dd $set dd 0)
but this doesn’t work
)
*Step4. Match HH and DD sets in a loop
*Finally, I want to generate a parameter that matches hh1->dd1, hh2->dd2 and hh3->dd3 (this is another part I’m having trouble figuring out, here’s the end result I want, but in a loop):
parameter x(hh);
x(“hh1”)=%dd1%;
x(“hh2”)=%dd2%;
x(“hh3”)=%dd3%;
Finally, these are generic names so I can’t just make a third set /1 2 3 4…/ as a suffix. Any help would be appreciated, thanks!
Update: So I managed to get it to work through some janky code, which I hope to improve and learn more GAMs through. The below code works, but is horribly inelegant…
*Step 1. define household set:
set hh /hh1 hh2 hh3 hh4 hh5 hh6/;
*Step2. manually define double dash parameters: (if someone knows how to loop this, it would be fantastic)
$if not set sim_1 $set sim_1 11
$if not set sim_2 $set sim_2 11
$if not set sim_3 $set sim_3 11
$if not set sim_4 $set sim_4 11
$if not set sim_5 $set sim_5 11
$if not set sim_6 $set sim_6 11
$if not set sim_7 $set sim_7 11 (<- this one is redundant, but I am setting up more than I currently need since “set hh” needs to be dynamically updated)
*Step3. Define parameter:
parameter simulation(h,sim);
*Step4. Feed double-dash values into “simulation(h,sim)”:
loop(h,
if(ord(h)=1,
simulation(h,“simid”)=%sim_1%);
if(ord(h)=2,
simulation(h,“simid”)=%sim_2%);
if(ord(h)=3,
simulation(h,“simid”)=%sim_3%);
if(ord(h)=4,
simulation(h,“simid”)=%sim_4%);
if(ord(h)=5,
simulation(h,“simid”)=%sim_5%);
if(ord(h)=6,
simulation(h,“simid”)=%sim_6%);
if(ord(h)=7,
simulation(h,“simid”)=%sim_7%);
);
I guess the real question now is how to streamline this code, hopefully using loops to generate the double-dash parameters… Thanks in advance for any tips/suggestions.