Announcement

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

  • Exporting data into a do file?

    Hi all,

    I am doing a bunch of analysis on data, and then saving the data in the following format:

    Click image for larger version

Name:	stata picture.png
Views:	1
Size:	9.4 KB
ID:	1368254


    My goal is to create a second do file that calls these globals. Right now what I do is manually copy and paste the output above into a do file. I am wondering if there is any way to export stata "data" directly into a do file?

    Thanks for your help.

  • #2
    Try -help file write- to see how you can write these globals into a do-file as you create them.

    That said, don't use globals for this. Global macros are inherently dangerous: their names can clash with global macros defined in other programs (which you may not even know are active when you run yours) and cause bizarre bugs that are nearly impossible to debug. Use local macros instead: they are only defined within their own program, or the scope of a do-file. Now, if you do switch to local macros as I suggest, and store them in a do-file, then simply -run-ning that do file will no longer be effective, because the local macros would go out of scope as soon as that defining do-file finishes running. So what you need to do instead is to -include- that do-file in your code wherever it is needed.

    Comment


    • #3
      Code:
      forvalues i = 1/`=_N' {
          local `=_varname[`i']' `= b[`i']'
      }
      will create local macros b_SeTvC_fam_insecurity with value -.0046742 and b_Se2vC_fam_insecurity with value -.1295136, etc. I use locals instead of globals for the reasons Clyde mentioned.
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        On the question: whether [slight editing]

        there is any way to export Stata "data" directly into a do file
        dataex (SSC) almost does that. You just need to take its output and save as a .do file.

        I don't regard global macros as data, however.

        Comment

        Working...
        X