FUKUGAWA Nobuya wrote:
I have a dataset that has several blank cells represented as
period (.) and generated tables as follows.
year cat var1
1950 1 .
1950 1 .
1950 2 3
1960 1 7
1960 2 1
1960 2 5
bys year: table cat , c(mean var1)
Stata returns;
year = 1950
cat
2 3
year = 1960
cat
1 7
2 3
The results of cat==1 if year==1950 is unreported since
observations are blank.
Here, I would like all the tables to retain the same number of rows.
Namely,
year = 1950
cat var1
1 .
2 3
year = 1960
cat var1
1 7
2 3
How can I do this using Stata 9?
--------------------------------------------------------------------------------
There are undoubtedly better ways, some of which might take advantage of
user-written modules, but I'd try something like either of the approaches
illustrated in the do-file below. The first uses -table-, but in a
different manner from what you show, and the second uses -collapse-
and -list-.
The first produces output like this:
----------------------
| cat
year | 1 2
----------+-----------
1950 | 3
1960 | 7 3
----------------------
and the second like this:
+------------------------+
| year cat mean_var1 |
|------------------------|
| 1950 1 . |
| 1950 2 3 |
|------------------------|
| 1960 1 7 |
| 1960 2 3 |
+------------------------+
Joseph Coveney
clear
set more off
input int year byte cat byte var1
1950 1 .
1950 1 .
1950 2 3
1960 1 7
1960 2 1
1960 2 5
end
// First
table year cat, contents(mean var1)
// Second
collapse (mean) mean_var1 = var1, by(year cat)
list, noobs sepby(year) abbreviate(`=length("mean_var1")')
exit
*
* 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/