Announcement

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

  • Issue opening a saved gph file on Stata (Stata/IC 16.0 for Mac (64-bit Intel) Revision 08 Jan 2020)

    I'm receiving an error message when I try to open a graph that I had previously created in stata and saved in the format .gph.

    When I created the graph, I used the following command:

    . graph twoway (connected us_10 Year, lpattern(solid) msymbol(s)) (connected it_10 Year, lpattern(dash) msymbol(d)), legend(label(1 "United States") label(2 "Italy")) ytitle("Income Share") xtitle("The Top Decile Income Share, 1980-2014") xlabel(1980(10)2014) title("Figure 1") saving("Figure1-hw2.gph", replace)

    The graph was created with no issues, it is only when I try to open the saved version that I receive the following error message:

    too few quotes
    error (132) reading file
    Error in file, skipping lines:
    USA
    Pre-tax national income
    varlist not allowed
    r(101);

    I'm having trouble figuring out where exactly the problem is occurring and how I can fix it. Does anyone have any insight into how to resolve this issue?

  • #2
    I assume the gph file was NOT edited after it was created.

    By any chance does your dataset have hidden line-feed/carriage-return
    characters in any variable labels or value labels?

    The following assumes this is the source of the problem and shows how to
    fix your dataset.


    Fix broken variable labels in dta

    If you re-apply each variable's label, Stata will automatically
    strip-out any line-break/carriage-returns in the original label string.

    Code:
    foreach v of varlist * {
            local label : variable label `v'
            label variabel `v' `"`label'"'
    }

    Find and fix broken value labels in dta

    The easiest way to find broken value labels is to save them to a do-file.

    Code:
    label dir
    label save `r(names)' using check-labels.do
    doedit check-labels.do
    The resulting file check-labels.do should contain calls to
    label define, which define each value label, one value at a
    time. Each call to label define should be contained within a
    single line.

    If there are any quoted strings broken over multiple lines in
    check-labels.do, join them back into a single line, and save the
    do-file.

    To recreate the value labels, type the following in Stata:

    Code:
    label drop _all
    do check-labels.do
    Once your dataset has been fixed, you should be able to create a
    graph useable gph-file.

    Comment


    • #3
      If you do not have access to the data, you should be able to fix the gph
      file with a good text file editor like Vim. Do not try to use
      Stata's do-file editor to fix the gph-file; the binary part of the
      gph-file may not be handled properly.


      Find and fix broken labels in gph

      For broken variable labels, search for lines starting with
      .label. In a valid gph file, they look like

      Code:
       
      .label = `"Mileage (mpg)"'
      and should be contained within a single line in that file. Suppose my
      dataset was constructed outside of Stata (by a third party application)
      and they mistakenly put a line feed after Mileage, then this line in the
      gph file would look something like

      Code:
      .label = `"Mileage
      (mpg)"'
      Stata will not be able to read this gph file.
      To fix this, join the string into a single line.


      Find and fix broken value labels in gph

      Search for lines starting with .vlabs.Declare. In a valid gph
      file, they look like

      Code:
       
      .vlabs.Declare __D_0 = `"Domestic car"'
      and should be contained within a single line in that file. Suppose my
      dataset was constructed outside of Stata (by a third party application)
      and they mistakenly put a line feed after Domestic, then this line in the
      gph file would look something like

      Code:
      .vlabs.Declare __D_0 = `"Domestic
      car"'
      (mpg)"'
      Stata will not be able to read this gph file.
      To fix this, join the string into a single line.

      Comment

      Working...
      X