Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Country-Industry pair correlation as a variable

    Dear all,
    I am new to Statalist, and this is my first post. Thank you in advance for your support and guidance.
    I am using Stata 16.
    I have industry-level output for a set of home and destination countries covering 20 years and 15 industries.
    I am estimating the effects of business cycle correlations between two countries of the export value. I would like to calculate and generate as a variable the correlation between the industry level output in the home country and the destination country. This is what my data looks like in brief: where h_go is industry level output in home country and go is industry output in destination country.

    Click image for larger version

Name:	data.jpg
Views:	1
Size:	45.6 KB
ID:	1614432

    I have tried the following code but it is not working:

    Code:
    sort home destination ind
     egen corr_ind = corr(h_go go), by(home destination ind)
    I would appreciate any advice on this issue.
    Thanks.

  • #2
    The command -statsby- is a possibility. It will create a new data set with all the correlation coefficients, and then you can save the data and merge them back to the big data set. Here is an example using nlsw88 data (a built-in data set in Stata):

    Code:
    clear
    sysuse nlsw88
    
    statsby r(rho), by(race married union): pwcorr wage hours
    list, sep(0)
    Output:
    Code:
         +----------------------------------------+
         |  race   married      union     _stat_1 |
         |----------------------------------------|
      1. | white    single   nonunion    .1765345 |
      2. | white    single      union   -.0888096 |
      3. | white   married   nonunion    .1585188 |
      4. | white   married      union    .0085371 |
      5. | black    single   nonunion    .2635747 |
      6. | black    single      union   -.1452858 |
      7. | black   married   nonunion    .1885973 |
      8. | black   married      union   -.0517299 |
      9. | other    single   nonunion   -.2958906 |
     10. | other    single      union          -1 |
     11. | other   married   nonunion    .6153787 |
     12. | other   married      union     .368683 |
         +----------------------------------------+

    Comment


    • #3
      Ken shows one way, another way is what you have tried, and statements such as "I have tried the following code but it is not working" are not useful because you do not say how the code you tried fails to deliver what you want. It is best if you show exactly what you typed at Stata, and exactly what Stata returned, and then with reference to this explain what you do not like about the outcome.

      The -egen,corr()- is part of the egenmore package. So you need to firstly
      Code:
       ssc install egenmore
      to install the package.



      Comment


      • #4
        Dear Ken Chui,
        Thank you for your reply.
        I will try it and see what happens.

        Dear Joro Kolev,
        Thank you for the remark, will stick to your suggestion to show clearly what part does not work. I have installed the egenmore package. In fact, I have been using the GDP correlations well, but the results for my industry level correlations have an issue.
        I will try to describe it better.
        Thanks.

        Comment

        Working...
        X