Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Tab, Matrix, & Capturing Frequencies

From   "Fraser, Steven" <>
To   "Statalist (E-mail)" <>
Subject   st: Tab, Matrix, & Capturing Frequencies
Date   Fri, 8 Nov 2002 11:17:53 -0500


Assume the following variation on the auto data:

Manuf	Brand	Model		MPG	Cost	....
Ford	Merc	Mountaineer
Ford	Ford	Explorer
Ford	Ford	Escape
GM	GM	Yukon
GM	Chev	Tahoe
Chry	Dodge	Durango
Chry	Dodge	Durango
Ford	Ford	Escape
Ford	Ford	Escape	
GM	Chev	Blazer

I am trying to capture the number of models offered by the 'brand' Ford as
opposed to the 'manufacturer' Ford.  If I sort by brand (assuming only one
manufacturer for now..I will complicate with more manufacturers) and then
tab brand and model, I get results depicting the frequency of each model
(i.e. Explorer 1, Escape 3 for 'brand' Ford and Mountaineer 1 for 'brand'
Merc).  What I need is to capture the value '2' indicating 2 models for the
'brand' Ford and '1' indicating 1 model for the 'brand' Merc.  The only way
I have been able to capture this is when I add the 'matcell' command (help
from a FAQ) and then capturing the number of rows.  However, even while I am
currently only using one 'manufacturer', I have several 'brands' and need
the number of models offered by each 'brand', but matrix will only return
the matrix for the last 'brand' and matrix cannot be used with by.  The
simple code I am using is as follows:

sort brand
by brand: tab model brand, matcell(x)
list matrix x

Any help is greatly appreciated.

Steve Fraser
Univ of South Florida
(813) 974-9680

*   For searches and help try:

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