Announcement

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

  • Exporting subset of data as a table into Latex

    Hi,
    I have cross-sectional data with both both string (area names) and numeric (hours worked, wages, et cetra) variables.
    I am trying to create a table with specific observations only and export it to Latex.

    The problem is equivalent to using "auto" database in Stata and trying to create a table which displays variables (make, price, foreign) in a side-by-side fashion that can be exported as .tex output.
    Code:
    sysuse auto, clear
     br make price foreign if mpg<20 | mpg>35
    While there are many commands and references online for exporting regression or two-way output tables to Latex, I have not been able to find something for simply exporting a subset of data as a formatble table into Latex.

    Any help would be highly appreciated. Thank you.

  • Andrew Musau
    replied
    Originally posted by Arvind Sharma View Post
    I am trying to create a table with specific observations only and export it to Latex.

    The problem is equivalent to using "auto" database in Stata and trying to create a table which displays variables (make, price, foreign) in a side-by-side fashion that can be exported as .tex output.
    Code:
    sysuse auto, clear
    br make price foreign if mpg<20 | mpg>35
    While there are many commands and references online for exporting regression or two-way output tables to Latex, I have not been able to find something for simply exporting a subset of data as a formatble table into Latex.

    Simple operations such as taking the mean by observation do not transform the data. Therefore, this provides scope for using commands that export estimates to export data. For your example, I use estout from the Stata Journal to illustrate some technique.

    Code:
    sysuse auto, clear
    isid make
    encode make, gen(Make)
    eststo clear
    quietly estpost tabstat price foreign if mpg<20 | mpg>35, by(Make)
    esttab, cells("price(label(`:var lab price')) foreign(label(`:var lab foreign'))") ///
    noobs nomtitle nonumber varlabels(`e(labels)') varwidth(20) drop(Total) tex
    Res.:

    Code:
    {
    \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
    \begin{tabular}{l*{1}{cc}}
    \hline\hline
                        &       Price&    Car type\\
    \hline
    AMC Pacer           &        4749&           0\\
    Audi 5000           &        9690&           1\\
    Buick Electra       &        7827&           0\\
    Buick LeSabre       &        5788&           0\\
    Buick Riviera       &       10372&           0\\
    Buick Skylark       &        4082&           0\\
    Cad. Deville        &       11385&           0\\
    Cad. Eldorado       &       14500&           0\\
    Chev. Impala        &        5705&           0\\
    Chev. Nova          &        3955&           0\\
    Dodge Diplomat      &        4010&           0\\
    Dodge Magnum        &        5886&           0\\
    Dodge St. Regis     &        6342&           0\\
    Linc. Continental   &       11497&           0\\
    Linc. Mark V        &       13594&           0\\
    Linc. Versailles    &       13466&           0\\
    Merc. Cougar        &        5379&           0\\
    Merc. Marquis       &        6165&           0\\
    Merc. Monarch       &        4516&           0\\
    Merc. XR-7          &        6303&           0\\
    Olds Cutl Supr      &        5172&           0\\
    Olds Cutlass        &        4733&           0\\
    Olds Delta 88       &        4890&           0\\
    Olds Omega          &        4181&           0\\
    Olds Toronado       &       10371&           0\\
    Peugeot 604         &       12990&           1\\
    Plym. Volare        &        4060&           0\\
    Pont. Catalina      &        5798&           0\\
    Pont. Firebird      &        4934&           0\\
    Pont. Grand Prix    &        5222&           0\\
    Pont. Le Mans       &        4723&           0\\
    Pont. Phoenix       &        4424&           0\\
    Toyota Celica       &        5899&           1\\
    Toyota Corona       &        5719&           1\\
    VW Diesel           &        5397&           1\\
    Volvo 260           &       11995&           1\\
    \hline\hline
    \end{tabular}
    }

    Leave a comment:


  • Nicolas GomezParra
    replied
    You can map the labels to the first observation and then export the data

    Leave a comment:


  • Arvind Sharma
    replied
    Thank you Carole. The program also does not use labels but the variable name itself when exporting the table. Any suggestions to get around that ? Renaming would not work here.

    Leave a comment:


  • Carole J. Wilson
    replied
    The program -dataout- written by Roy Wada and available on SSC seems to do what you want. I don't know if it takes -if- statements, but you can always -keep- the data you want (after -preserve-ing the data if necessary).

    Leave a comment:

Working...
X