Announcement

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

  • Two graphs in one from matrix using _matplot or other command

    I would like to define a matrix, like the following one:
    Code:
    matrix input test = (7, 60, 90 \ 8, 50, 85 \  9, 40, 80 \ 10, 30, 75 \ ...)
    and I would like to use the matrix content to create two graphs in one from it where the first column would define the x-axis and the second and third column would yield two separate lines within the same graph. The result should look similar to the excel graph I attached below.

    I tried
    Code:
    _matplot
    but the description in the help file is very clear about the fact that it is only designed for two columns (i.e. one graph). Are there any other solutions to my problem?
    Click image for larger version

Name:	graph.PNG
Views:	2
Size:	74.7 KB
ID:	1374505


  • #2
    Typically I just first preserve the data in memory, turn the matrix into a Stata dataset, create my graph, and than restore the original data again.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you. This seems reasonable. In the end, I used svmat and saved all matrices as seperate data sets. Here is the code (for future readers with the same question):

      Code:
              * Construct a data set from each matrix
              foreach sector in "11" "21" "22" "23" "31" "32" "33" "42" "44" "45" "48" "49" "51" "52" "53" "54" "55" "56" "61" "62" "71" "72" "81" {
                  svmat c_`sector', names(col)
                  keep years c_low c_mid c_high
                  keep if years != .
                  save "data/temp/c_`sector'.dta", replace
                  clear
              }

      Comment

      Working...
      X