Announcement

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

  • How to extract a country specific value for each country in a panel data set

    I have a panel date set wich consists of 49 countries and want to extract fed funds rate for each country. The variable interestrate have interest rate of each country and want to extract the values of the US
    interestrate for each country in the data set.

  • #2
    Arbnor:
    do you mean something along the following lines?:
    Code:
    . use "http://www.stata-press.com/data/r15/nlswork.dta"
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . bysort idcode: egen flag=mean(ln_wage)
    
    . list idcode ln_wage flag in 1/10
    
         +------------------------------+
         | idcode    ln_wage       flag |
         |------------------------------|
      1. |      1   1.451214   2.040433 |
      2. |      1    1.02862   2.040433 |
      3. |      1   1.589977   2.040433 |
      4. |      1   1.780273   2.040433 |
      5. |      1   1.777012   2.040433 |
         |------------------------------|
      6. |      1   1.778681   2.040433 |
      7. |      1   2.493976   2.040433 |
      8. |      1   2.551715   2.040433 |
      9. |      1   2.420261   2.040433 |
     10. |      1   2.614172   2.040433 |
         +------------------------------+
    
    . list idcode ln_wage flag if idcode==1
    
           +------------------------------+
           | idcode    ln_wage       flag |
           |------------------------------|
        1. |      1   1.451214   2.040433 |
        2. |      1    1.02862   2.040433 |
        3. |      1   1.589977   2.040433 |
        4. |      1   1.780273   2.040433 |
        5. |      1   1.777012   2.040433 |
           |------------------------------|
        6. |      1   1.778681   2.040433 |
        7. |      1   2.493976   2.040433 |
        8. |      1   2.551715   2.040433 |
        9. |      1   2.420261   2.040433 |
       10. |      1   2.614172   2.040433 |
           |------------------------------|
       11. |      1   2.536374   2.040433 |
       12. |      1   2.462927   2.040433 |
           +------------------------------+
    
    .
    Please note that, with no example/excerpt of your data, every reply draws heavily on guess-work.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      I am not looking to do that.


      Click image for larger version

Name:	1.PNG
Views:	1
Size:	15.2 KB
ID:	1522644


      What I want to do is like in this photo. I have countries and years and the interest rate variable from which I want to take the values of the USA and create the newvar as I did in the USintrate.
      So, the new variable should contain only US interest rate for each county in the sample.












      Comment


      • #4
        Please read FAQ 12 on how to present data examples.

        Code:
        preserve
        keep if country=="USA"
        keep year intrate
        rename intret Usintret
        tempfile usint
        save `usint'
        restore
        merge m:1 year using `usint'
        drop _merge
        l, sepby(country)
        Last edited by Andrew Musau; 30 Oct 2019, 11:24.

        Comment


        • #5
          Andrew Musau is bang on: the data example in #3 is far from what we ask for in FAQ Advice #12 . It's an image and not amenable to copy and paste.

          Here is a silly example of similar form and a simpler way to get at what is requested. Notice, please, that most of the work is setting up a data example here.


          Code:
          * data example 
          clear 
          set obs 16 
          gen country = word("USA Italy Germany France", ceil(_n/4)) 
          egen year = seq(), from(1990) to(1993) 
          gen intrate = _n 
          
          
          * this does the work 
          egen usintrate = total((country == "USA") * intrate), by(year) 
          
          list, sepby(country) 
          
              +-------------------------------------+
               | country   year   intrate   usintr~e |
               |-------------------------------------|
            1. |     USA   1990         1          1 |
            2. |     USA   1991         2          2 |
            3. |     USA   1992         3          3 |
            4. |     USA   1993         4          4 |
               |-------------------------------------|
            5. |   Italy   1990         5          1 |
            6. |   Italy   1991         6          2 |
            7. |   Italy   1992         7          3 |
            8. |   Italy   1993         8          4 |
               |-------------------------------------|
            9. | Germany   1990         9          1 |
           10. | Germany   1991        10          2 |
           11. | Germany   1992        11          3 |
           12. | Germany   1993        12          4 |
               |-------------------------------------|
           13. |  France   1990        13          1 |
           14. |  France   1991        14          2 |
           15. |  France   1992        15          3 |
           16. |  France   1993        16          4 |
               +-------------------------------------+
          For a more systematic discussion, see https://www.stata-journal.com/articl...article=dm0055

          Comment

          Working...
          X