Announcement

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

  • How to Plot Mean scores in Panel Data

    Dear Stata Users,

    I have a panel dataset with 50 countries over 19 years. I wish to plot mean scores for some variables on an x-y plane. This would normally be done with xtline var if I was just interested line plots for individual units.
    Let's assume my dependent variable is Y, and my explanatory variables are X and Z. I would like to plot the mean scores of X & Y, and Z & Y so as to establish the average behaviour of the data over time. Given that this is a panel data, I have had challenges in doing so. Please, kindly advise me on how to proceed.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float fdistock int bits float economicfreedom byte democ
     3378.873 29 56.8 1
    4491.9785 33 57.3 1
      5556.94 35   61 1
      6194.82 38 57.7 1
      7076.68 40 58.1 3
    end
    Kind regards

    NB. Please, this is my first time of using dataex, kindly notify me if my example is not correct.

  • #2
    I can't see a country identifier or a time variable in your data example. As I understand it, you want to average acriss the panels. This is code you can run in your Stata.


    Code:
    . webuse grunfeld, clear
    
    . egen mean_invest = mean(invest), by(year)
    
    . line mean_invest year if company == 1


    Here if company == 1 isn't essential, but it is a reminder that the mean values are repeated for each company (panel).

    Comment


    • #3
      Thank you, Nick Cox, for your response. Although I did not provide the right dataset, your response has solved my problem. Please, how could I have generated a sample data with country and time identifiers using panel data? This should help me next time.

      Kind Regards

      Comment


      • #4
        You don't need to. Just phrase your problem in terms of the Grunfeld data.

        Comment

        Working...
        X