I have a panel data set that consists of portfolio weights of 25 different currencies (called "Weight'name of country'") and net return currency spot rates of those 25 countries (called "netreturn_Spot'name of country'") which are both sorted by column. My goal is to compute portfolio returns per country based on a carry investment strategy.
I tried to “merge” several loop commands to multiply net spot returns of each country by the portfolio weight of the respective country.
I created the loop command as follows:
Code:
foreach var of varlist SpotCzechRepublic - netreturn_SpotUK { foreach `y' of nettreturn_Spot {CzechRepublic Mexico Austria Belgium Denmark France Germany Italy Netherlands Portugal Spain Iceland Israel Canada Norway Sweden Switzerland UnitedStates Greece Hungary Japan Poland SouthKorea SlovakRepublic UK foreach `x' of Weight {UK UnitedStates Poland Portugal SlovakRepublic Spain Sweden Switzerland Japan SouthKorea Mexico Netherlands Norway Greece Hungary Iceland Israel Italy France Germany CzechRepublic Denmark Canada Belgium Austria gen pfreturn = Weight`y' * netreturn_Spot`x' if `x'==`y' } } }
Since I am a beginner, I don’t know whether I am on a complete wrong path or I just did a small syntax error. I also noticed in other discussions that you have to define a local first and then run those local variables in one loop, but I failed to apply it in my particular case...
It would be great if somebody could help me out!
Thanks,
Hans
0 Response to Multiple loop commands into one, "program error: code follows on the same line as open brace”
Post a Comment