Statalist


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

RE: st: storing tables and values in tables


From   Maarten buis <[email protected]>
To   [email protected]
Subject   RE: st: storing tables and values in tables
Date   Thu, 28 Feb 2008 09:35:27 +0000 (GMT)

There are many ways of doing what you want, which one is best for you
depends on what you want to do with them. 

> (a) Suppose I create the following table:
> 
> tab jobclass sex, row nofreq
> 
>             |         1          2 |     Total
> -----------+----------------------+----------
>          1 |     97.35       2.65 |    100.00 
>          2 |     73.53      26.47 |    100.00 
> -----------+----------------------+----------
>      Total |     77.61      22.39 |    100.00 
> 
> is there a way for me to save one of the values in the table to a
> variable or scalar? For example, suppose I want to create a variable
> x equal to the value contained in cell (2,1), x = 73.53. How can I do
> this?


The proportions aren't saved, but the counts are. The easiest way is to
use the -proportion- command.

*-------- begin example ---------------
sysuse auto, clear
recode rep78 1/2=3
tab rep78 foreign, row nofreq

proportion rep78 if foreign == 1
di [rep78]_b[3]
*--------------- end example ------------- 
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
 
> (b) Now, is there a way to save the whole table above to a matrix?
> Hopefully, without having to do (a) repeatedly many times?

*------------- begin example ----------
sysuse auto, clear
proportion rep78, over(foreign)
matrix list e(b)
*-------------- end example -----------
 
> And one more question: if I do something like
> 
> reg depvar var1 var2 var3 var4
> 
> I will obtain the regression output that Stata provides. Can I save
> the stuff in the regression output to other variables? For instance,
> if I want the estimate and the standard errors of the coefficient of
> var3, and I want to put them in a scalar x1 and x2, respectively, how
> do I do this?

see -help ereturn-
*----------- begin example -----------
sysuse auto, clear
reg mpg trunk length
erturn list
matrix list e(b)
di _se[trunk]
di _b[trunk]
*------------ end example -------------

Hope this helps,
Maarten

-----------------------------------------
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.docs.yahoo.com/nowyoucan.html
*
*   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