Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: st: AW: Formatting tables with estpost & esttab


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: AW: Formatting tables with estpost & esttab
Date   Tue, 6 Oct 2009 15:02:20 +0200

<> 

This will give you four separate csvs and open them:


*************
sysuse auto, clear
xtile price3= price, nq(3)
xtile weight3= weight, nq(3)
xtile mpg3= mpg, nq(3)

foreach var of varlist rep price3 weight3 mpg3{
  estpost tab `var' for, chi2
	esttab  using example`var'.csv,  /* 
	*/ main(b) aux(colpct) nostar plain /* 
	*/ unstack noobs nonum nonote/*
  */ sca("chi2 Chi2 Value" "p corr. p-value")  /* 
	*/ sfmt(%4.3fc) wide compress replace
}

foreach var of varlist rep price3 weight3 mpg3{
	!start example`var'.csv
}
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Eduardo Nunez
Gesendet: Dienstag, 6. Oktober 2009 14:56
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: AW: Formatting tables with estpost & esttab

Hi Martin,

I tried to loop the code applying estpost&esttab over several
variables, but no success yet. Below is the code.
The idea is to save into Excel for further manipulation.

----------------------------------------------------------------------------
-------
sysuse auto, clear
xtile price3= price, nq(3)
xtile weight3= weight, nq(3)
xtile mpg3= mpg, nq(3)

tempname hdle
capt erase info.dta

postfile `hdle' str10 var n1 colperc1 /*
*/ n2 colperc2 pval overalln overallcolperc /*
*/ using info

foreach var of varlist rep price3 weight3 mpg3{
       estpost tab `var' for, chi2
	   eststo
	   esttab *, main(b) aux(colpct) nostar unstack noobs nonum nonote
sca("chi2 Chi2 Value" "p corr. p-value") sfmt(%4.3fc) wide compress,
using example.csv, replace
}

postclose `hdle'

use info, clear
l, abbrev(12) noobs sep(0)
----------------------------------------------------------------------------
-------

Thank you in advance,

Eduardo




2009/10/5 Martin Weiss <martin.weiss1@gmx.de>:
>
> <>
>
> I assume you want the p-value for the F-test in -oneway-? If so:
>
> **************
> webuse apple, clear
> oneway weight treatment
> di Ftail(r(df_m),r(df_r),r(F) )
> **************
>
> Re several variables it would be helpful to know where you want the
results
> to end up. Is it a csv file or a tex file or something else? Depending on
> the answer to this question, you can of course loop with -forach var of
> varlist- and dump the results into a file...
>
>
>
> HTH
> Martin
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Eduardo Nunez
> Sent: Montag, 5. Oktober 2009 19:48
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: AW: Formatting tables with estpost & esttab
>
> Martin,
>
> This is the code you sent me for discrete variables:
>
> ***
> sysuse auto, clear
>
> estpost tab rep for, chi2
> esttab ., main(b) aux(colpct)  /*
> */ nostar unstack noobs nonum nonote  /*
> */ sca("chi2 Chi2 Value" "p corr. p-value")  /*
> */ sfmt(%4.3fc) wide compress
>
> ***
>
> It works for just one variable. However, how do I loop over several
> variables? I used tab2, firstonly but it seems estpost doesn't
> recognize it.
> I also tried to adapt the program for continuous variables but this
> time when the stratifying variable is categorical with several levels
> (3,4, 5 levels). I tried to use oneway, but it did not store the
> p-value.
> How should I get it? Also, can I reuse the same program, when using
> stratifying variables with diferent levels? Or it must be created
> tailored for the same number of levels? For instances a program for 3
> levels, another for 4 levels and so on.
>
>
> Best wishes,
>
> Eduardo
>
>
>
> 2009/10/5 Martin Weiss <martin.weiss1@gmx.de>:
>>
>> <>
>>
>>
>> Add the -detail- option to your -summarize-s! You are asking for stuff
> that
>> Stata only releases upon request :-)
>>
>>
>>
>> HTH
>> Martin
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: owner-statalist@hsphsun2.harvard.edu
>> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Eduardo
Nunez
>> Gesendet: Montag, 5. Oktober 2009 17:10
>> An: statalist@hsphsun2.harvard.edu
>> Betreff: Re: st: AW: Formatting tables with estpost & esttab
>>
>> Hi Martin,
>>
>> Stata/MP 11.0 for Windows (64-bit x86-64)
>> Born 26 Aug 2009
>> Copyright (C) 1985-2009
>>
>> Total physical memory:     4191812 KB
>> Available physical memory: 2227852 KB
>>
>> Single-user 2-core Stata perpetual license:
>>       Serial number:  XXXXXXXXXXXX
>>         Licensed to:  Eduardo Nunez
>>                       Personal license
>>
>>
>> I tried to adapt the code for means-SD and ttest to medians IQR and
>> median unsuscefully. Below is the code. I get the p-value for each
>> variable but not the descriptive statistics.
>> What am i doing wrong?
>>
>> Here is the code:
>>
>> **********************
>> use "C:\Users\Eduardo\Desktop\HF dataset - August 24,
>> 2009\Longitudinal_lymphocyte_analysis.dta", clear
>> tempname hdle
>> capt erase info.dta
>> postfile `hdle' str10 var Median_0 IQR25_0 IQR75_0 /*
>> */  Median_1 IQR25_1 IQR75_1 pval Overallmedian OverallIQR25 OverallIQR75
> /*
>> */ using info
>>
>> foreach var of varlist los edad_b fc_ingreso tas_ingreso tad hb leucos
>> neutrofilos linfocitos monocitos cr acurico colesterol ldl hdl tga na{
>>       sum `var' if !sexo
>>       loc Median_0=r(p50)
>>       loc IQR25_0=r(p25)
>>           loc IQR75_0=r(p75)
>>       sum `var' if sexo
>>       loc Median_1=r(p50)
>>       loc IQR25_1=r(p25)
>>           loc IQR75_1=r(p75)
>>       median `var', by(sexo) exact
>>       local pval=r(p_exact)
>>       sum `var'
>>       post `hdle' ("`var'") (`Median_0') (`IQR25_0') (`IQR75_0') /*
>>       */ (`Median_1') (`IQR25_1') (`IQR75_1') (`pval') /*
>>       */ (r(p50)) (r(p25)) (r(p75))
>> }
>>
>> postclose `hdle'
>>
>> use info, clear
>> l, abbrev(12) noobs sep(0)
>> *********************************************************
>> Thisw is the result I got:
>>
>
+---------------------------------------------------------------------------
>> -------------------------------------------------------+
>>  |        var   Median_0   IQR25_0   IQR75_0   Median_1   IQR25_1
>> IQR75_1       pval   Overallmed~n   OverallIQR25   OverallIQR75 |
>>
>>
>
|---------------------------------------------------------------------------
>> -------------------------------------------------------|
>>  |        los          .         .         .          .         .
>>    .   .4098835              .              .              . |
>>  |     edad_b          .         .         .          .         .
>>    .   .0000138              .              .              . |
>>  | fc_ingreso          .         .         .          .         .
>>    .   .6778672              .              .              . |
>>  | tas_ingres          .         .         .          .         .
>>    .    .000103              .              .              . |
>>  |        tad          .         .         .          .         .
>>    .   .4437288              .              .              . |
>>  |         hb          .         .         .          .         .
>>    .   7.24e-11              .              .              . |
>>  |     leucos          .         .         .          .         .
>>    .   .0460077              .              .              . |
>>  | neutrofilo          .         .         .          .         .
>>    .     .00087              .              .              . |
>>  | linfocitos          .         .         .          .         .
>>    .    .833713              .              .              . |
>>  |  monocitos          .         .         .          .         .
>>    .   1.11e-06              .              .              . |
>>  |         cr          .         .         .          .         .
>>    .   1.36e-08              .              .              . |
>>  |    acurico          .         .         .          .         .
>>    .   .0039871              .              .              . |
>>  | colesterol          .         .         .          .         .
>>    .   7.56e-08              .              .              . |
>>  |        ldl          .         .         .          .         .
>>    .   .0002156              .              .              . |
>>  |        hdl          .         .         .          .         .
>>    .   .0047893              .              .              . |
>>  |        tga          .         .         .          .         .
>>    .   1.35e-09              .              .              . |
>>  |         na          .         .         .          .         .
>>    .   .6747179              .              .              . |
>>
>>
>
+---------------------------------------------------------------------------
>> -------------------------------------------------------+
>>
>>
>> One more thing...
>> The code you sent me for discrete variables:
>> ***
>> sysuse auto, clear
>>
>> estpost tab rep for, chi2
>> esttab ., main(b) aux(colpct)  /*
>> */ nostar unstack noobs nonum nonote  /*
>> */ sca("chi2 Chi2 Value" "p corr. p-value")  /*
>> */ sfmt(%4.3fc) wide compress
>>
>> ***
>> How do I loop over several variables? I used tab2, firstonly but it
>> seems estpost doesn't recognize it.
>>
>>
>>
>> Note: In biomedical sciences these are the traditional way to express
>> table 1 for the manuscript where you show how baseline characteristics
>> are distributed over your exposure variable.
>> I imagine a lot of statalister that work in biomedical science would
>> take advantage of this automatic process to save time.
>>
>> I am very grateful of your help and excuse my ignorance in Stata
> programing.
>>
>> Best wishes,
>>
>> Eduardo
>>
>>
>>
>>
>>
>> 2009/10/5 Martin Weiss <martin.weiss1@gmx.de>:
>>>
>>> <>
>>>
>>> Not sure how you would get the upper panel into esttab, but you can sure
>> get
>>> it into a Stata file which you could export in any way you see fit...
>>>
>>>
>>> *************
>>> sysuse auto, clear
>>>
>>> tempname hdle
>>>
>>> capt erase info.dta
>>>
>>> postfile `hdle' str10 var dommean domsd /*
>>> */ formean forsd pval overallmean overallsd /*
>>> */ using info
>>>
>>>
>>> foreach var of varlist price mpg{
>>>        sum `var' if !for
>>>        loc dommean=r(mean)
>>>        loc domsd=r(sd)
>>>        sum `var' if for
>>>        loc formean=r(mean)
>>>        loc forsd=r(sd)
>>>        ttest `var', by(foreign)
>>>        local pval=r(p)
>>>        sum `var'
>>>        post `hdle' ("`var'") (`dommean') (`domsd') /*
>>>        */ (`formean') (`forsd') (`pval') /*
>>>        */ (r(mean)) (r(sd))
>>> }
>>>
>>> postclose `hdle'
>>>
>>> use info, clear
>>> l, abbrev(12) noobs sep(0)
>>> *************
>>>
>>>
>>>
>>> HTH
>>> Martin
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: owner-statalist@hsphsun2.harvard.edu
>>> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Eduardo
> Nunez
>>> Gesendet: Montag, 5. Oktober 2009 01:18
>>> An: statalist@hsphsun2.harvard.edu
>>> Betreff: Re: st: AW: Formatting tables with estpost & esttab
>>>
>>> Hi Martin,
>>>
>>> It did work pretty good for discrete variables. For continuous
>>> variables, I would like a code that provide me side by side the
>>> meanpuls-minusSD for the two categories of Foreign and a third column
>>> with the p-value from ttest.
>>>
>>> Thank you so much in advance,
>>>
>>> Eduardo
>>>
>>>
>>>
>>> On Sun, Oct 4, 2009 at 5:36 PM, Martin Weiss <martin.weiss1@gmx.de>
> wrote:
>>>>
>>>> <>
>>>>
>>>>
>>>>
>>>> You can -estpost- all these results in a quite straightforward manner,
>> and
>>>> then -esttab- them with the matrix function of this command.  For
>>> instance,
>>>> the lower panel of your table would be
>>>>
>>>> ***
>>>> sysuse auto, clear
>>>>
>>>> estpost tab rep for, chi2
>>>> esttab ., main(b) aux(colpct)  /*
>>>> */ nostar unstack noobs nonum nonote  /*
>>>> */ sca("chi2 Chi2 Value" "p corr. p-value")  /*
>>>> */ sfmt(%4.3fc) wide compress
>>>>
>>>> ***
>>>>
>>>>
>>>>
>>>> HTH
>>>> Martin
>>>>
>>>>
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: owner-statalist@hsphsun2.harvard.edu
>>>> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Eduardo
>> Nunez
>>>> Gesendet: Sonntag, 4. Oktober 2009 22:33
>>>> An: statalist@hsphsun2.harvard.edu
>>>> Betreff: st: Formatting tables with estpost & esttab
>>>>
>>>> Dear statalister,
>>>>
>>>> I have been trying to get the right code in estpost and esttab
>>>> (without success) to format tables as the example below (using auto
>>>> dataset):
>>>>
>>>>                         Domestic (N=52)                Foreign (N=22)
>>>> P-value         Total (N=74)
>>>>
>>>> Price                       6179.3ą3189.0               6070.1ą2221.0
>>>> 0.015           6146.0ą2912.4
>>>>
>>>> Mileage (mpg)                  19.54ą4.753              25.29ą6.310
>>>> 0.006           21.29ą5.866
>>>>
>>>> Repair Record 1978, n(%)
>>>> *0.000
>>>> 1                                2 (4.17)
>>>> 0 (0)
>>>>        2 (2.9)
>>>> 2                               8 (16.67)
>>>> 0 (0)
>>>>        8 (11.59)
>>>> 3                               27 (56.25)
>>>> 3 (14.29)                               30 (43.48)
>>>> 4                               9 (18.75)
>>>> 9 (42.86)                               18 (26.09)
>>>> 5                               2 (4.17)
>>>> 9 (42.86)                               11 (15.94)
>>>>
>>>> *Omnibus P-value
>>>>
>>>>
>>>>
>>>>
>>>> The meanąSD  [or median (IQR) when appropriate] for each variable and
>>>> for the total population with the p-value corresponding (either a
>>>> t-test or ranksum test);
>>>> For discrete variables, the n (%)...count(col percentage) and the
>>>> p-value corresponding to chi2.
>>>>
>>>> I would really appreciate any help on this issue.
>>>>
>>>> Best wishes,
>>>>
>>>> Eduardo
>>>>
>>>> *
>>>> *   For searches and help try:
>>>> *   http://www.stata.com/help.cgi?search
>>>> *   http://www.stata.com/support/statalist/faq
>>>> *   http://www.ats.ucla.edu/stat/stata/
>>>>
>>>>
>>>> *
>>>> *   For searches and help try:
>>>> *   http://www.stata.com/help.cgi?search
>>>> *   http://www.stata.com/support/statalist/faq
>>>> *   http://www.ats.ucla.edu/stat/stata/
>>>>
>>>
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/statalist/faq
>>> *   http://www.ats.ucla.edu/stat/stata/
>>>
>>>
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/statalist/faq
>>> *   http://www.ats.ucla.edu/stat/stata/
>>>
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index