Announcement

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

  • Plotting mean values for 4 variables across 3 years

    Hi all,

    I have a panel dataset and I am trying to create a line graph of the mean values for 4 variables across 3 years.
    • The variables are: csh_sh; cc_sh; dc_sh; chk_sh
    • They are continuous variables taking values between 0 and 1
    • I want to show the mean value for each variable for each year
    I am struggling to find the correct code for this. Any help would be much appreciated - thanks


  • #2
    Code:
    foreach v in  csh_sh cc_sh dc_sh  chk_sh {
        egen mean_`v' = mean(`v'), by(year)
        label var mean_`v' "`v'"
    }
    
    line mean_* year, ytitle(Annual means)

    Comment


    • #3
      Thanks very much Nick!

      I was also wondering how to plot a bar chart for age with the Y-axis being mean values of the continuous variable “csh_sh”, X-axis being years 2015-2017, and a key for different age groups denoted by “agecat”.

      I have managed to create a bar chart for csh_sh across different age categories using the following code:

      Code:
      graph bar csh_sh, by(agecat)
      However, this does not split the results for each year on the X-axis as I’d like.

      Many thanks again and apologies for the follow up question on a slightly different problem.
      Last edited by sladmin; 11 May 2020, 08:01. Reason: anonymize original poster

      Comment


      • #4
        I have managed to create a bar graph using the following code. However, it produces 3 graphs for different years....ideally I would be able to show this in one graph.

        Code:
        graph bar csh_sh, over(agecat),  by(year)
        Last edited by sladmin; 11 May 2020, 08:01. Reason: anonymize original poster

        Comment


        • #5
          #4 answers #3 but for the record and for later readers the syntax given would fail as the second comma is illegal. over() and by() are both options.

          Comment

          Working...
          X