Hi everyone,
I have a time series set of monthly currency spot rates from multiple countries. I also have portfolio weigths per currency of those countries in the same set (see pic 1), which is supposed to be launched as a carry investment strategy.
What I wanted to do is to create a loop command in order to compute net spot returns per country. Then I would like create another loop to multiply those monthly net spot returns by the portfolio weights per country.
I first tested it for the country of Austria, according to the following formula, which worked out fine btw:
gen time = _n
gen spotlogreturns2 =(((SpotAustria[_n]) - (SpotAustria[_n-1])) / (SpotAustria[_n]))
gen PfReturnsAustria = ((spotlogreturns2[_n]) * (WeightAustria[_n]))
Then I created a loop for the net spot returns based on that formula as follows:
foreach var of varlist SpotCzechRepublic - SpotUK {
gen netreturn_`var' = (((`var’[_n]) - (`var’[_n-1])) / (`var’[_n]))
}
However, I received error r(198) code dislaying "`var' invalid name"(see pic2). Do you guys have an idea of what went wrong here? SInce, I am a beginner I am not even sure whether I set the loop command right. It would be great if somebody could help me with this!
Thank you guys so much,
Hans
Related Posts with Beginner question, loop command for net returns, error code r(198) "`var' invalid name"
Questions about "xtrifreg" - Unconditional quantile regression with fixed effects?Dear Statalists, (1) Can anyone help me check robustness for xtrifreg please? And how can I run sim…
DV DifferencesHi all, In my regression, I should enter Y(t1)-Y(t0) as a dependent variable where t1 and t0 are 10…
Rearranging data using stata codeDear Stata Users, I would like to rearrange the following data sets using a specific "stata-code" r…
Ologit: conditional marginal effect and semi-elastictyDear All, After estimating an ordered logit model, I want to to calculate and draw the plot of cond…
Meta-analysis of individual patient data (one-step) - time to event in the presence of competing-risksHi, I am wondering whether anyone can help with a problem I am having synthesizing data for a meta-…
Subscribe to:
Post Comments (Atom)
0 Response to Beginner question, loop command for net returns, error code r(198) "`var' invalid name"
Post a Comment