Announcement

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

  • Combining confidential data: Overlaying graphs from different datasets

    My colleagues and I have access to separate confidential datasets on municipal water use. Each person has access to one dataset; we cannot easily share them with each other without negotiating new data agreements with water utilities. We are trying to do parallel analyses but combine our results in overlaid graphs.

    Here is an analogy using Stata's "auto" dataset. My code below plots a simple scatterplot of weight against mpg separately for foreign and domestic automakers. The first graph is what we want: an overlay of data from the two. But suppose that the data on domestic automakers was stored in a separate file on a separate computer (owned by Mauricio) from the data on foreign automakers (owned by me). Can Mauricio and I generate separate scatterplots, output them (to .gph?), and them combine them somehow to recreate the first graph?

    Code:
    clear
    use https://www.stata-press.com/data/r7/auto.dta
    twoway (scatter weight mpg if foreign==0, mcolor(red)) (scatter weight mpg if foreign==1, mcolor(black)), legend(label(1 "Domestic") label(2 "Foreign"))
    
    use https://www.stata-press.com/data/r7/auto.dta, clear
    keep if foreign==0
    twoway (scatter weight mpg if foreign==0, mcolor(red))
    *save how?
    
    use https://www.stata-press.com/data/r7/auto.dta, clear
    keep if foreign==1
    twoway (scatter weight mpg if foreign==1, mcolor(black))
    *save how?
    
    *graph combine?

  • #2
    not completely sure I understand, but if you can get both gph files on the same computer, preferably in the same directory, then you can easily use graph combine - or is there something more complicated in your situation that I am not understanding?

    Comment


    • #3
      But -graph combine- will not produce an overlay as far as I am aware. It will create a two-panel graph, where each panel contains one of the originals.

      Comment


      • #4
        Yes, Clyde is correct. I know we can create a panel of two separate graphs, but we can't overlay them into one (like the first graph in my example)

        Comment


        • #5
          Originally posted by Joe Cook View Post
          But suppose that the data on domestic automakers was stored in a separate file on a separate computer (owned by Mauricio) from the data on foreign automakers (owned by me). Can Mauricio and I generate separate scatterplots, output them (to .gph?), and them combine them somehow to recreate the first graph?
          Yes. The GPH file stores the data. See #6 https://www.statalist.org/forums/for...mbomarginsplot and

          Code:
          help serset

          Comment

          Working...
          X