Hey! I'm having trouble with the following code in Stata, which is supposed to plot lines for real data and predicted data for each Bundesland (i from 1 to 9), with a legend indicating which line corresponds to which data:
forvalues i = 1/9 { twoway (line rel_Energiekonsum Jahr if Bundesland == `i', lcolor(black) lpattern(solid)) (line yhat Jahr if Bundesland == `i', lcolor(blue) lpattern(dash)) , legend(order(1 "Real data" 2 "Predicted data") lcolor(black blue)) xtitle("Year") ytitle("rel_Energiekonsum") title("Predicted vs. real data for Bundesland `i'") }
However, the plot doesn't appear as intended, and I'm not sure what the issue is (only the real data is plottet). I've already double-checked that the closing brace } is present at the end of the code, but I'm not sure if there are other issues with the code itself or with my data. The data used "Jahr" and "Bundesland" are used to create the panel. Bundesland is cathegorical from 1 to 9.
Here the error messege:
forvalues i = 1/9 {
2.
. twoway (line rel_Energiekonsum Jahr if Bundesland == `i', lcolor(black) lpattern(solid))
3.
. (line yhat Jahr if Bundesland == `i', lcolor(blue) lpattern(dash))
4.
. , legend(order(1 "Real data" 2 "Predicted data") lcolor(black blue))
5.
. xtitle("Year") ytitle("rel_Energiekonsum") title("Predicted vs. real data for Bundesland `i'")
6.
. }
( is not a valid command name
r(199);
Could someone help me identify the issue and suggest a possible solution? Any help would be greatly appreciated!
forvalues i = 1/9 { twoway (line rel_Energiekonsum Jahr if Bundesland == `i', lcolor(black) lpattern(solid)) (line yhat Jahr if Bundesland == `i', lcolor(blue) lpattern(dash)) , legend(order(1 "Real data" 2 "Predicted data") lcolor(black blue)) xtitle("Year") ytitle("rel_Energiekonsum") title("Predicted vs. real data for Bundesland `i'") }
However, the plot doesn't appear as intended, and I'm not sure what the issue is (only the real data is plottet). I've already double-checked that the closing brace } is present at the end of the code, but I'm not sure if there are other issues with the code itself or with my data. The data used "Jahr" and "Bundesland" are used to create the panel. Bundesland is cathegorical from 1 to 9.
Here the error messege:
forvalues i = 1/9 {
2.
. twoway (line rel_Energiekonsum Jahr if Bundesland == `i', lcolor(black) lpattern(solid))
3.
. (line yhat Jahr if Bundesland == `i', lcolor(blue) lpattern(dash))
4.
. , legend(order(1 "Real data" 2 "Predicted data") lcolor(black blue))
5.
. xtitle("Year") ytitle("rel_Energiekonsum") title("Predicted vs. real data for Bundesland `i'")
6.
. }
( is not a valid command name
r(199);
Could someone help me identify the issue and suggest a possible solution? Any help would be greatly appreciated!
Comment