Hello,

I am using Stata 15.1 and I have two datasets. There are two economic values in each dataset for a shared set of countries, each dataset containing one of two different time periods. One has 23 variables with 118 observations. The second dataset has 93 variables with 118 observations. The first variable stores the names of countries. Each variable after stores numerical values for a given year across each of these countries in chronological order, each country being a different observation. Half of the variables measure one economic value across the years (GDP) and the other half measures the other value across those same years (Population Density). I am looking to generate a variable which stores REGRESS values, specifically R-squared, between the two different kinds of variables across the given years.

Conceptually it's like this as an example. Observation 1 (Country A) has Variable 1 (v1): Country Name, Variable 2 (v2gdp): Year 1 GDP, Variable 3: Year 2 GDP etc. until Variable 13 (v2): Year 1 Population Density, Variable 14: Year 2 Population Density etc. I am trying to have each economic value paired with the other economic value for the same year, and across the many years for that country. It should be an X and Y plot that I am performing the REGRESS function on where X contains the values of economic value 1 across the timeframe and Y contains the values of economic value 2 across the timeframe. I then want to store the R-Squared value for each observation in a new variable.

I am not sure how to treat the data across these variables as an X and Y pair that I can perform REGRESS on. I am not sure what code to use when generating a new variable that stores the REGRESS R-Squared information. I use v1 v2 v3 formatting for the one set of variables and v1gdp v2gdp v3gdp as the name format for the second set of variables to differentiate what kind of economic value they are storing. If anything needs clarifying please let me know.

Thank You