Hi, there is a similar thread on this question, but it doesn't make sense for my case. I have filled in choice experiment data to create observations for the alternatives not chosen by the respondent and need to copy down the values of certain other variables within groups of choice sets and by person. I have 2 lines of code that work to do this and need to be repeated ~5 times to catch all the changes. It works fine manually but I want to know if there's a simpler way to code it to repeat until r(N)=0.
Here is the code:
bys hhid choiceset: replace choicecode=choicecode[_n-1] //
if (choicecode==. & hhid==hhid[_n-1] & choiceset==choiceset[_n-1])
bys hhid choiceset: replace choicecode=choicecode[_n+1] //
if (choicecode==. & hhid==hhid[_n+1] & choiceset==choiceset[_n+1])
I know one way is to use forval and just tell it to automatically run 5 times, but that is the same as manual and it is taking a long time to run this code and might be faster if I tell it to stop whenever there are no more changes to make.
Thanks so much,
Kate
Here is the code:
bys hhid choiceset: replace choicecode=choicecode[_n-1] //
if (choicecode==. & hhid==hhid[_n-1] & choiceset==choiceset[_n-1])
bys hhid choiceset: replace choicecode=choicecode[_n+1] //
if (choicecode==. & hhid==hhid[_n+1] & choiceset==choiceset[_n+1])
I know one way is to use forval and just tell it to automatically run 5 times, but that is the same as manual and it is taking a long time to run this code and might be faster if I tell it to stop whenever there are no more changes to make.
Thanks so much,
Kate
Comment