I want to create a series of graphs with -tabplot- from Stata Journal. The categories on the x- and y-axis should be fixed in order to recognise the patterns better. But when I select certain observations a number of categories will have no obsverations. At the moment the graph displays bars at categories where there are no observations. I do not know which trick I need to do...
The example includes a variable (luf_t_m) as subjects, a variable with sources (fwl_i) and a variable with publication types (pubtype) and an observation id-variable (core_id). Overall, I would like to present subjects by sources and to see if the contribution of sources differ by publication type I limit it e.g. to books (pubtype==2).
Here is the code which is quite lengthy because I manipulate the labels but I wanted it to be as realistic as possible to my own code:

Any idea, where I missed something.
The example includes a variable (luf_t_m) as subjects, a variable with sources (fwl_i) and a variable with publication types (pubtype) and an observation id-variable (core_id). Overall, I would like to present subjects by sources and to see if the contribution of sources differ by publication type I limit it e.g. to books (pubtype==2).
Here is the code which is quite lengthy because I manipulate the labels but I wanted it to be as realistic as possible to my own code:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int luf_t_m byte fwl_i int core_id byte pubtype
290 0 28285 5
400 0 28647 1
490 0 28155 1
490 0 28785 1
400 0 28816 1
410 0 28033 1
360 0 27547 5
490 0 27724 5
490 0 28213 1
490 0 27942 1
235 0 28623 1
410 0 28665 1
490 0 28657 2
490 0 28443 1
490 0 28401 1
490 1 7265 1
490 1 11203 1
490 1 10855 1
410 1 8839 1
490 1 3950 1
360 1 4943 1
370 1 3223 1
490 1 6075 1
360 1 3080 1
400 1 1754 1
490 1 2647 1
400 1 2940 1
540 1 2615 1
410 1 3139 1
370 1 1878 1
765 2 3042 4
470 2 10726 1
490 2 3795 1
470 2 11427 1
490 2 5144 1
315 2 12418 1
490 2 7471 1
315 2 7865 1
80 2 12483 1
370 2 9428 1
490 2 2295 1
540 2 10839 1
400 2 9460 1
490 2 2707 1
235 2 2620 1
235 3 10572 4
315 3 6129 1
290 3 4978 3
765 3 1282 3
765 3 1944 4
370 3 4010 1
490 3 8096 1
490 3 2127 1
490 3 12588 1
765 3 8276 4
470 3 1364 1
400 3 8975 1
400 3 5257 3
490 3 7081 4
400 3 5471 1
490 4 25586 3
410 4 22196 3
490 4 17802 3
490 4 26623 1
490 4 26847 1
490 4 21351 2
490 4 17913 1
540 4 18126 4
490 4 26690 2
490 4 24218 1
490 4 23466 2
490 4 25590 3
490 4 26252 3
490 4 27232 5
320 4 21154 4
490 5 30654 5
490 5 30313 5
80 5 31104 1
490 5 29812 5
490 5 29674 5
410 5 31106 1
490 5 31088 5
490 5 31991 1
80 5 30397 4
490 5 31117 5
490 5 31744 1
470 5 30186 5
490 5 31692 5
490 5 29984 1
690 5 30510 5
470 6 14649 1
470 6 13276 1
400 6 15603 1
765 6 13483 2
315 6 15609 1
400 6 14861 1
490 6 16870 1
490 6 13492 1
315 6 29577 1
490 6 13454 3
490 6 14154 1
490 6 16530 3
490 6 29604 1
370 6 16879 1
490 6 16688 3
490 7 13995 5
400 7 14817 1
490 7 13180 1
490 7 13807 5
340 7 16231 1
490 7 14227 1
470 7 13458 1
490 7 15130 1
400 7 14140 1
490 7 14004 5
490 7 15097 5
490 7 15081 5
490 7 17367 5
470 7 14717 5
490 7 14698 1
end
label values luf_t_m l_luf_t
label def l_luf_t 50 "G", modify
label def l_luf_t 80 "L", modify
label def l_luf_t 235 "So", modify
label def l_luf_t 290 "Wi", modify
label def l_luf_t 315 "Ps", modify
label def l_luf_t 360 "Ph", modify
label def l_luf_t 370 "Ch", modify
label def l_luf_t 400 "Bi", modify
label def l_luf_t 410 "Ge", modify
label def l_luf_t 470 "Klt", modify
label def l_luf_t 490 "Klp", modify
label def l_luf_t 520 "Za", modify
label def l_luf_t 540 "Ve", modify
label def l_luf_t 610 "Ag", modify
label def l_luf_t 690 "Ma", modify
label def l_luf_t 765 "In", modify
label values fwl_i l_fwl_i
label def l_fwl_i 0 "not in x", modify
label def l_fwl_i 1 "in x", modify
label def l_fwl_i 2 "in x1", modify
label def l_fwl_i 3 "in x2", modify
label def l_fwl_i 4 "in x3", modify
label def l_fwl_i 5 "in x4", modify
label def l_fwl_i 6 "in x5", modify
label def l_fwl_i 7 "in x6", modify
label values pubtype l_pubtype
label def l_pubtype 1 "Article", modify
label def l_pubtype 2 "Book", modify
label def l_pubtype 3 "Book Chapter", modify
label def l_pubtype 4 "Proceedings", modify
label def l_pubtype 5 "Other", modify
********************* Selection of Publication type
keep if pubtype==2
*********************
*******************************
label copy l_fwl_i l_fwl_i_cs
label copy l_luf_t l_luf_t_cs
la val fwl_i l_fwl_i_cs
la val luf_t_m l_luf_t_cs
*levelsof fwl_i, local(fwli)
foreach fwl of num 0/7 {
qui sum core_id if fwl_i == `fwl'
local ls = `r(N)'
local s = `"`ls'"'
local vl: label l_fwl_i `fwl'
local vlt = `"`vl' (N=`s')"'
la de l_fwl_i_cs `fwl' `"`vlt'"', modify
local fwln`fwl' = `"(N=`s')"'
local fwls`fwl' = `"`vl'"'
}
levelsof luf_t_m, local(ltm)
foreach lt of local ltm {
qui sum core_id if luf_t_m == `lt'
local ls = `r(N)'
local s = `"`ls'"'
local vl: label l_luf_t `lt'
local vlt = `"`vl' (N=`s')"'
la de l_luf_t_cs `lt' `"`vlt'"', modify
}
qui sum core_id, d
local total = `r(N)'
tabplot luf_t_m fwl_i , separate(fwl_i) percent(luf_t_m) showval(,mlabs(vsmall) mlabg(zero) ) xtitle("") ytitle("") subtitle(`"N=`total'"') ///
xlabel(1 `""`fwls0'" "`fwln0'""' 2 `""`fwls1'" "`fwln1'""' 3 `""`fwls2'" "`fwln2'""' 4 `""`fwls3'" "`fwln3'""' 5 `""`fwls4'" "`fwln4'""' 6 `""`fwls5'" "`fwln5'""' 7 `""`fwls6'" "`fwln6'""' 8 `""`fwls7'" "`fwln7'""', labs(vsmall)) ylabel(, labs(vsmall)) name(tabp_dataex, replace) ///
xsc(titlegap(*1.1)) height(.6) ///
note("", span)
Any idea, where I missed something.

Comment