I'm trying to use the tabulate
command in Stata to create a time series of frequencies. The problem arises when I try to combine the output of tabulate
after running through each date. tabulate
will not include 0 as an entry when no observation exists for a value of the variable in question. For instance, if I wanted to count the 10, 11 and 12 year olds in a class over a three-year period Stata might output (8) if only one of the groups were represented and thus we don't know which group the 8 students belonged to: it could be (0,8,0) or (0,0,8).
This is not a problem if the time series is short as the "Results" window shows which categories are or are not represented. I have a much longer time series to my data. Does anyone know of a solution/method that forces Stata to include zeroes in these tabulations? The relevant parts of my code follows:
# delimit;
set more off;
clear;
matrix drop _all;
set mem 1200m;
cd ;
global InputFile "/Users/.../1973-2010.dta";
global OutputFile "/Users/.../results.txt";
use $InputFile;
compress;
log using "/Users/.../log.txt", append;
gen yr_mn = ym(year(datadate), month(datadate));
la var yr_mn "Year-Month Date"
xtset, clear;
xtset id datadate, monthly;
/*Converting the Ratings Scale to Numeric*/;
gen LT_num = .;
replace LT_num = 1 if splticrm=="AAA";
replace LT_num = 2 if (splticrm=="AA"||splticrm=="AA+"||splticrm=="AA-");
replace LT_num = 3 if (splticrm=="A"||splticrm=="A+"||splticrm=="A-");
replace LT_num = 4 if (splticrm=="BBB"||splticrm=="BBB+"||splticrm=="BBB-");
replace LT_num = 5 if (splticrm=="BB"||splticrm=="BB+"||splticrm=="BB-");
replace LT_num = 6 if (splticrm=="B"||splticrm=="B+"||splticrm=="B-");
replace LT_num = 7 if (splticrm=="CCC"||splticrm=="CCC+"||splticrm=="CCC-");
replace LT_num = 8 if (splticrm=="CC");
replace LT_num = 9 if (splticrm=="SD");
replace LT_num = 10 if (splticrm=="D");
summarize(yr_mn);
local start = r(min);
local finish = r(max);
forv x = `start'/`finish' {;
qui tab LT_num if yr_mn == `x', matcell(freq_`x');
};
log close;