Dear Stata community,

I'm using time series regression using data of 100 countries over 22 years to estimate the effect of financial openness on economic development. However, I'm running into an endogeneity problem: Openness may lead to higher growth, but countries that expect to grow a lot may tend to open up their economies. To control for this issue I want to control for recent growth trends. Specifically, I want to control for the average growth rate over the past three years. I'm not sure if there is an easy way to add this into the regression or if I have to create new variables. Does anyone have an idea how to do this?

Thank you in advance for your time.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str42 country int year float loggdppc double(ka gdppcg)
"Algeria" 1995 9.137277                 1 1.853423792861392
"Algeria" 1996 9.160067               .75 2.305087244845765
"Algeria" 1997 9.154971                 1 -.508245295794012
"Algeria" 1998 9.189805               .75 3.544786287223985
"Algeria" 1999 9.207232               .75 1.758011109300668
"Algeria" 2000 9.231221              .875 2.427875700928467
"Algeria" 2001 9.247847              .875 1.676475843908534
"Algeria" 2002 9.289751 .9285714285714286 4.279453026560546
"Algeria" 2003 9.346609 .9285714285714286 5.850520833432341
"Algeria" 2004 9.375616 .9285714285714286 2.943232296389624
end