My mentor suggests using Excel to make tables for a systematic review we're doing, but this to me is unacceptable, so I must learn the table command. I have some experience with using it, but there's a particular issue I've ran across, namely extracting the occurrence of substrings in a variable and counting them. Let's look at my sample data. Note that I use tabsplit by Nick Cox
The issue here is that some studies use multiple different designs. Table 1 produces
Table two gives us
I would like to use the table command to make table 2. The issue is that the tabsplit command doesn't allow me to extract the underlying dataset/matrix used to make the table.
So what I suppose I want, is to count the occurrence of the strings in quotes, make a table from these strings, and have the rows to the table be labelled by the string itself. How might I do this?
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str64 design
`""DID""'
`""BA""'
`""XS""'
`""DID""'
`""DID" "SCM""'
`""SCM""'
`""BA""'
`""CHT""'
`""DID""'
`""DID""'
`""CHT""'
`""XS""'
`""DID""'
`""DID""'
`""XS""'
`""DID""'
`""XS""'
`""DID""'
`""DID""'
`""DID" "SCM""'
`""XS""'
`""CHT""'
`""DID" "SCM""'
`""CBA""'
`""BA""'
`""ITS""'
`""CHT""'
`""BA""'
`""BA""'
`""DID" "IVE""'
`""XS""'
`""DID""'
`""DID""'
`""DID""'
`""DID" "SCM""'
`""DID""'
`""BA""'
`""XS""'
`""DID""'
`""DID""'
`""DID""'
`""BA""'
`""DID" "RDD""'
`""CBA""'
`""CHT""'
`""ITS""'
`""DID""'
`""DID""'
`""BA""'
`""BA""'
`""DID""'
`""DID""'
`""DID""'
`""DID" "SCM""'
`""XS""'
`""DID""'
`""BA""'
`""DID""'
`""DID""'
`""DID""'
`""DID""'
`""DID""'
`""XS""'
`""BA""'
`""DID" "IVE""'
`""DID" "SCM""'
`""DID""'
`""XS""'
`""ITS""'
`""DID""'
`""XS""'
`""XS""'
`""DID""'
`""BA""'
`""DID""'
`""XS""'
`""SCM""'
`""DID""'
`""DID""'
`""CBA""'
`""ITS""'
`""DID""'
`""DID""'
`""DID""'
`""DID""'
`""ITS""'
`""ITS""'
`""DID""'
`""DID" "SCM""'
`""DID""'
`""DID""'
`""DID""'
`""CHT""'
`""BA""'
`""XS" "BA""'
`""ITS""'
`""XS""'
`""SCM""'
`""XS""'
`""PH""'
end
cls
cap qui which sencode
if _rc {
qui ssc inst sencode, replace
}
preserve
sencode design, replace
*Table 1
table design
restore
cap qui which tabsplit
if _rc {
qui net inst tab_chi.pkg, replace
}
*Table 2
tabsplit design, parse(`"""') sort
Code:
--------------------------
| Frequency
--------------+-----------
design |
"DID" | 41
"BA" | 13
"XS" | 15
"DID" "SCM" | 7
"SCM" | 3
"CHT" | 6
"CBA" | 3
"ITS" | 7
"DID" "IVE" | 2
"DID" "RDD" | 1
"XS" "BA" | 1
"PH" | 1
Total | 100
--------------------------
Code:
design | Freq. Percent Cum.
------------+-----------------------------------
DID | 51 45.95 45.95
XS | 16 14.41 60.36
BA | 14 12.61 72.97
SCM | 10 9.01 81.98
ITS | 7 6.31 88.29
CHT | 6 5.41 93.69
CBA | 3 2.70 96.40
IVE | 2 1.80 98.20
PH | 1 0.90 99.10
RDD | 1 0.90 100.00
------------+-----------------------------------
Total | 111 100.00
So what I suppose I want, is to count the occurrence of the strings in quotes, make a table from these strings, and have the rows to the table be labelled by the string itself. How might I do this?

Comment