Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Summarize and Tabulate


From   Gauri Khanna <[email protected]>
To   <[email protected]>
Subject   RE: st: Summarize and Tabulate
Date   Wed, 16 Jan 2008 18:38:40 +0000

Thank you Maarten for posting my request and for your help on the question. You are right about using encode, - destring-or  -generate-would have been better.

Gauri

> Date: Wed, 16 Jan 2008 15:47:39 +0000
> From: [email protected]
> Subject: st: Summarize and Tabulate
> To: [email protected]; [email protected]
>
> Gauri had trouble posting the message below on statalist. So here is my
> attempt.
>
> I also think I what went wrong. My idea is that while transforming sbp
> (string) to sbpnew (numeric), Gauri inadvertantly created a variable
> with values 1, 2, 3, 4, ..., which were given value labels 100, 102,
> 103, 104 (the measured bloodpresure). So when computing summary
> statistics Stata looks at the actual values of the variables (1, 2, 3,
> ...) while when tabulating Stata displays the value labels (100, 102,
> 103, ...).
>
> If that is the case, than the following remark from the help file of
> -encode- may be relevant:
>
> Do not use encode if varname contains numbers that merely happen to be
> stored as strings; instead, use -generate newvar = real(varname)- or
> -destring-.
>
> Hope this helps,
> Maarten
>
>
> --- Gauri Khanna  wrote:
>> Dear Statalist,
>>
>>
>> I have run into an odd problem. I have a variable called sbpnew
>> (which is systolic blood pressure measured in mm/Hg). I created
>> sbpnew from its original variable sbp which was a string variable.
>>
>> I used –summarize- to look at the mean and the minimum and maximum
>> values of sbpnew. The maximum value stated is 116 but when I
>> –tabulate sbpnew- I observe many values in the 200 range. I also
>> generated a histogram using –histogram sbpnew – and again I get a
>> maximum value in the histogram of around 116. I copy parts of my log
>> file showing the output.
>>
>>
>> Could any one advise on why the –summarize- measure and the
>> –tabulate- measure are different?
>>
>> Thank you,
>>
>> Ms. Gauri
>>
>>
>> India
>>
>>
>> OUTPUT FROM LOGFILE
>>
>> /*Merging the two datasets*/
>> . use database2
>> . sort id
>> . save database2, replace
>> file database2.dta saved
>>
>> . use database1
>> . sort id
>> . save database1, replace
>> file database1.dta saved
>>
>> . merge id using database2
>> . tabulate _merge
>>
>>
>> _merge | Freq. Percent Cum.
>>
>>
>> ------------+-----------------------------------
>>
>> 3 | 4,699 100.00 100.00
>>
>>
>> -----------+-----------------------------------
>>
>>
>> Total | 4,699 100.00
>>
>> . drop _merge
>> . /*merge completed*/
>>
>> . /*detecting outliers on sbp*/
>>
>> . describe
>> Contains data from database1.dta
>>
>> obs: 4,699
>> vars: 10 15 Jan 2008 16:09
>> size: 108,077 (99.9% of memory free)
>>
>>
> -------------------------------------------------------------------------------
>> storage display value
>>
>>
>> variable name type format label variable label
>>
> -------------------------------------------------------------------------------
>>
>> id int %8.0g
>> sbp str3 %9s
>> dbp int %8.0g
>> sex byte %8.0g
>> age byte %8.0g
>> scl int %8.0g
>> chdfate byte %8.0g CHDfate
>> followup int %8.0g
>> bmi str4 %9s
>> month byte %8.0g
>>
>>
> -------------------------------------------------------------------------------
>> Sorted by:
>> Note: dataset has changed since last saved
>>
>>
>> . /* sbp is a string variable and needs to be converted into numeric
>> first*/
>> . encode sbp, gen(sbpnew)
>> . summarize sbpnew
>>
>>
>> Variable | Obs Mean Std. Dev. Min
>> Max
>>
>>
>>
> -------------+--------------------------------------------------------
>> sbpnew | 4697 31.61486 21.29675 1
>> 116
>>
>> . tabulate sbpnew, miss
>>
>> sbpnew | Freq. Percent Cum.
>>
>> ------------+-----------------------------------
>> 100 | 64 1.36 1.36
>> 102 | 35 0.74 2.11
>> 103 | 3 0.06 2.17
>> 104 | 73 1.55 3.72
>> 105 | 47 1.00 4.72
>> 106 | 51 1.09 5.81
>> 107 | 1 0.02 5.83
>> 108 | 142 3.02 8.85
>> 109 | 2 0.04 8.90
>> 110 | 217 4.62 13.51
>> 112 | 145 3.09 16.60
>> 113 | 2 0.04 16.64
>> 114 | 128 2.72 19.37
>> 115 | 101 2.15 21.52
>> 116 | 113 2.40 23.92
>> 117 | 3 0.06 23.98
>> 118 | 160 3.40 27.39
>> 120 | 256 5.45 32.84
>> 121 | 1 0.02 32.86
>> 122 | 138 2.94 35.79
>> 123 | 1 0.02 35.82
>> 124 | 190 4.04 39.86
>> 125 | 95 2.02 41.88
>> 126 | 159 3.38 45.26
>> 127 | 1 0.02 45.29
>> 128 | 144 3.06 48.35
>> 129 | 1 0.02 48.37
>> 130 | 233 4.96 53.33
>> 131 | 1 0.02 53.35
>> 132 | 151 3.21 56.57
>> 133 | 6 0.13 56.69
>> 134 | 140 2.98 59.67
>> 135 | 92 1.96 61.63
>> 136 | 126 2.68 64.31
>> 137 | 3 0.06 64.38
>> 138 | 131 2.79 67.16
>> 139 | 3 0.06 67.23
>> 140 | 151 3.21 70.44
>> 142 | 81 1.72 72.16
>> 143 | 1 0.02 72.19
>> 144 | 96 2.04 74.23
>> 145 | 59 1.26 75.48
>> 146 | 61 1.30 76.78
>> 147 | 2 0.04 76.82
>> 148 | 94 2.00 78.83
>> 149 | 3 0.06 78.89
>> 150 | 101 2.15 81.04
>> 152 | 59 1.26 82.29
>> 154 | 56 1.19 83.49
>> 155 | 48 1.02 84.51
>> 156 | 53 1.13 85.64
>> 157 | 1 0.02 85.66
>> 158 | 54 1.15 86.81
>> 159 | 1 0.02 86.83
>> 160 | 75 1.60 88.42
>> 162 | 31 0.66 89.08
>> 164 | 29 0.62 89.70
>> 165 | 25 0.53 90.23
>> 166 | 17 0.36 90.59
>> 167 | 2 0.04 90.64
>> 168 | 38 0.81 91.44
>> 170 | 37 0.79 92.23
>> 172 | 14 0.30 92.53
>> 174 | 24 0.51 93.04
>> 175 | 11 0.23 93.28
>> 176 | 16 0.34 93.62
>> 178 | 12 0.26 93.87
>> 179 | 1 0.02 93.89
>> 180 | 31 0.66 94.55
>> 181 | 1 0.02 94.57
>> 182 | 7 0.15 94.72
>> 184 | 13 0.28 95.00
>> 185 | 8 0.17 95.17
>> 186 | 17 0.36 95.53
>> 188 | 12 0.26 95.79
>> 190 | 14 0.30 96.08
>> 192 | 13 0.28 96.36
>> 194 | 12 0.26 96.62
>> 195 | 6 0.13 96.74
>> 196 | 3 0.06 96.81
>> 198 | 3 0.06 96.87
>>
> === message truncated ===
>
>
> -----------------------------------------
> Maarten L. Buis
> Department of Social Research Methodology
> Vrije Universiteit Amsterdam
> Boelelaan 1081
> 1081 HV Amsterdam
> The Netherlands
>
> visiting address:
> Buitenveldertselaan 3 (Metropolitan), room Z434
>
> +31 20 5986715
>
> http://home.fsw.vu.nl/m.buis/
> -----------------------------------------
>
>
> __________________________________________________________
> Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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