Hi everyone,

I am running a cross-sectional random effects regression. And I want to generate a new variable that consists of the correlation between two variables (say x and y) for each country. For each country this value will be a constant for all observations, because the correlation of x and y doesn't change and is unique for each country.

Using the following command Stata gave me a long list of, essentially, correlation of x and y for each country.
Code:
bysort country: corr y x
However, I failed to find a code that could generate what I need, which is a new variable that contains all these values.

Appreciate if someone can help with this issue.