Announcement

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

  • Saving current data to tex format

    After cleaning the data, I am left with the following data:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str27 industry_ifr19 float(pr_us_93_14 pr_us_93_00 pr_us_00_14)
    "Automotive"                  91.91 27.57 64.34
    "Miscellaneous Manufacturing" 13.81     0 13.81
    "Electronics"                  11.6  1.61  9.99
    "Plastics and Chemicals"       8.19  1.84  6.35
    "Basic Metals"                 7.17     0  7.17
    "Metal Products"               5.59  2.89   2.7
    "Food and Beverages"           5.05  1.19  3.86
    "Industrial Machinery"         2.37     0  2.37
    "Minerals"                      .67     0   .67
    "Shipbuilding and Aerospace"    .54     0   .54
    "Wood and Furniture"            .14     0   .14
    "Paper and Printing"            .11     0   .11
    "Mining"                        .06     0   .06
    "Education and Research"        .06     0   .06
    "Textiles"                      .05     0   .05
    "Agriculture"                   .04     0   .04
    "Utilities"                     .03     0   .03
    "Construction"                  .02     0   .02
    "Services"                        0     0     0
    end
    Now, I wish to save this data as it is in tex format. Ideally, I only want the data without variable names. I have done this manually in LATEX and the .tex file looks like:
    Code:
    Automotive&91.91&27.57&64.34 \\
    
    Miscellaneous Manufacturing&13.81&0.00&13.81 \\
    
    Electronics&11.6&1.61&9.99 \\
    
    Plastics and Chemicals&8.19&1.84&6.35 \\
    
    Basic Metals&7.17&0.00&7.17 \\
    
    Metal Products&5.59&2.89&2.70 \\
    
    Food and Beverages&5.05&1.19&3.86 \\
    
    Industrial Machinery&2.37&0.00&2.37 \\
    
    Minerals&0.67&0.00&0.67 \\
    
    Shipbuilding and Aerospace&0.54&0.00&0.54 \\
    
    Wood and Furniture&0.14&0.00&0.14 \\
    
    Paper and Printing&0.11&0.00&0.11 \\
    
    Mining&0.06&0.00&0.06 \\
    
    Education and Research&0.06&0.00&0.06 \\
    
    Textiles&0.05&0.00&0.05 \\
    
    Agriculture&0.04&0.00&0.04 \\
    
    Utilities&0.03&0.00&0.03 \\
    
    Construction&0.02&0.00&0.02 \\
    
    Services&0.00&0.00&0.00 \\
    Is it possible to save the data in .tex format shown above directly from STATA?


  • #2
    Code:
    egen wanted = concat(*),p("&")
    file open wanted using "wanted.tex", replace write
    forv i = 1/`=_N'{
        file write wanted "`=wanted[`i']'\\" _newline(1)
    }
    file close wanted
    Note: edited to add more efficient solution.
    Last edited by Ali Atia; 16 Mar 2022, 20:22.

    Comment


    • #3
      Ali Atia: Great, it works. Any tips on how to get the values to 2 decimal places in the final file? The output your code creates takes values like .46 and 0 etc whereas I was hoping get 0.46 and 0.00.

      Comment


      • #4
        Code:
        egen wanted = concat(*),p("&") format("%3.2f")
        file open wanted using "wanted.tex", replace write
        forv i = 1/`=_N'{
            file write wanted "`=wanted[`i']'\\" _newline(1)
        }
        file close wanted

        Comment


        • #5
          Ali Atia: Thanks!

          Comment

          Working...
          X