Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Count Command in Stata

    Hello STATALIST,
    This is a silly question, but I need to create a table that shows the frequency of an item-response like the one below:
    N= is the number of respondents
    I tried using the "tab" command for each Independent Categorical Variable and exporting the result in excel, but these are 32 and I was hoping to find a quicker way. Any suggestions?
    Numbers in the cell are only used as an example...
    Not So Important (1) Slightly Important (2) Moderately Important (2) Very Importatat (4) N=
    independent Categorical Variable A 5 5 5 5 20
    Independent Categorical Variable B 5 5 5 5 20
    Independent Categorical Variable C 5 5 5 5 20
    Independent Categorical Variable D 5 5 5 5 20
    Independent Categorical Variable E 5 5 5 5 20














    Thanks and in advance for your help,
    Best Regards,

    Bonnie
    Last edited by Bonnie Vettori; 05 Sep 2019, 09:03. Reason: CUNT

  • #2
    Below is quick and dirty untested code which might give you the desired result:
    Code:
     putexcel set test.xlsx, replace 
     putexcel B1="Not so important" C1="Slightly important" D1="Moderately important" E1="Very important" F1="N="
    local varrow 2
    tempname catmat
    foreach var of varlist <Insert here the list of categorical variables>{
        tab `var', matcell(`catmat')
        putexcel F`varrow'= `r(N)'
        mat `catmat' = `catmat'' 
        putexcel A`varrow'=matrix(`catmat')
        local ++varrow
    }
    The code is first setting up the Excel file and then writing your desired values. I hope that you get the idea. There might be still more elegant solutions possible.

    Comment

    Working...
    X