Announcement

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

  • Problem with creating a variable using other variables

    Dear Statalist Forum Users,

    I have the following panel data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str6 region int year double value
    "Asia"   1969  .8525122404098511
    "Asia"   1969               1.03
    "Europe" 1971  .8506529331207275
    "Europe" 1971  .9506529331207275
    "US"     1973 1.0506529331207275
    "US"     1973 1.1506529331207276
    "Asia"   1969 1.2506529331207277
    "Asia"   1969 1.3506529331207278
    "Europe" 1972 1.4506529331207279
    "Europe" 1972  1.550652933120728
    "US"     1973  1.650652933120728
    "US"     1974 1.7506529331207281
    "Asia"   1970 1.8506529331207282
    "Asia"   1970 1.9506529331207283
    "Europe" 1973  2.050652933120728
    "Europe" 1973 2.1506529331207283
    "US"     1973 2.2506529331207283
    "US"     1973 2.3506529331207284
    end
    I need to create new variables (Asia, Europe, US) that calculate the mean of regional values for every year. I have trouble in creating these variables. I would highly appreciate your guidance on this.

    Looking forward to hearing from you.

    Kind regards,
    Firangiz

  • #2
    not sure I completely understand, but is this what you are looking for:
    Code:
    . bys region year: egen mean=mean(value)
    r; t=0.05 15:22:11
    
    . li, clean noo
    
        region   year       value       mean  
          Asia   1969   .85251224   1.120955  
          Asia   1969   1.2506529   1.120955  
          Asia   1969        1.03   1.120955  
          Asia   1969   1.3506529   1.120955  
          Asia   1970   1.9506529   1.900653  
          Asia   1970   1.8506529   1.900653  
        Europe   1971   .85065293   .9006529  
        Europe   1971   .95065293   .9006529  
        Europe   1972   1.4506529   1.500653  
        Europe   1972   1.5506529   1.500653  
        Europe   1973   2.0506529   2.100653  
        Europe   1973   2.1506529   2.100653  
            US   1973   2.2506529   1.690653  
            US   1973   2.3506529   1.690653  
            US   1973   1.0506529   1.690653  
            US   1973   1.6506529   1.690653  
            US   1973   1.1506529   1.690653  
            US   1974   1.7506529   1.750653

    Comment


    • #3
      Dear Rich,

      Many thanks! It worked.

      Kind regards,
      Firangiz

      Comment

      Working...
      X