Announcement

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

  • List of long string vars

    I am simply looking to get a list of all the different values of a string variable, but some of them are quite long (8-12 words long), as they represent different criminal offense descriptions.

    When I -tab- that var, they obviously all show up in a list, but many are cut off (e.g. it will say "Petty theft at.."). Is there a way to either simply print all of them in their entirety (I don't actually need the frequencies that -tab- provides), or to tell Stata to print out the full value in the -tab- output table? I made up some sample data here, if that's helpful.



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str40 chrg_description
    "THIS DESCRIPTION IS REALLY WAY TOO LONG FOR STATA"
    "SO HERE IS SOME RANDOM DATA THAT I MADE UP AS AN EXAMPLE"
    "THIS DESCRIPTION IS REALLY WAY TOO LONG FOR STATA"
    ​​​​​​​"SO HERE IS SOME RANDOM DATA THAT I MADE UP AS AN EXAMPLE"
    end
    Last edited by Anne Todd; 24 Aug 2020, 18:16. Reason: Sample data pasted strangely

  • #2
    Code:
    help list
    you might want to sort them first and only list if different from the preceding value

    Comment


    • #3
      There are two problems here, but one is self-inflicted injury. Your example data are truncated on input because str40 truncates the input. You need str56.


      Code:
      . di length("SO HERE IS SOME RANDOM DATA THAT I MADE UP AS AN EXAMPLE")
      56
      .

      Beyond that,
      tabulate does truncate as you say, as does table.

      One solution is
      groups from the Stata Journal. As "groups" is a common keyword, the best and otherwise unpredictable search term is its identifier in the Stata Journal.

      Code:
      . search st0496, entry
      
      Search of official help files, FAQs, Examples, and Stata Journals
      
      SJ-18-1 st0496_1  . . . . . . . . . . . . . . . . . Software update for groups
              (help groups if installed)  . . . . . . . . . . . . . . . .  N. J. Cox
              Q1/18   SJ 18(1):291
              groups exited with an error message if weights were specified;
              this has been corrected
      
      SJ-17-3 st0496  . . . . .  Speaking Stata: Tables as lists: The groups command
              (help groups if installed)  . . . . . . . . . . . . . . . .  N. J. Cox
              Q3/17   SJ 17(3):760--773
              presents command for listing group frequencies and percents and
              cumulations thereof; for various subsetting and ordering by
              frequencies, percents, and so on; for reordering of columns;
              and for saving tabulated data to new datasets
      Code:
      
      


      The write-up is thus at
      https://www.stata-journal.com/articl...article=st0496 (which will emerge from behind a paywall in a few weeks' time). The gist is accessible at https://www.statalist.org/forums/for...updated-on-ssc

      You should install the code from st0496_1 (if you repeat the search command above you will get a clickable link) or there is a copy at ssc install groups. The paywall does not affect the possibility of installing the code.

      groups can be as plain as you want:


      Code:
      . groups chrg
      
        +-------------------------------------------------------------------------------------+
        |                                         chrg_description   Freq.   Percent      %<= |
        |-------------------------------------------------------------------------------------|
        | SO HERE IS SOME RANDOM DATA THAT I MADE UP AS AN EXAMPLE       2     50.00    50.00 |
        |        THIS DESCRIPTION IS REALLY WAY TOO LONG FOR STATA       2     50.00   100.00 |
        +-------------------------------------------------------------------------------------+
      
      . 
      
      . groups chrg, show(none) noheader
        +----------------------------------------------------------+
        | SO HERE IS SOME RANDOM DATA THAT I MADE UP AS AN EXAMPLE |
        |        THIS DESCRIPTION IS REALLY WAY TOO LONG FOR STATA |
        +----------------------------------------------------------+
      .

      This answer is the same as Rich Goldstein's, insofar as groups uses list as its display engine.

      Comment


      • #4
        Thank you both!

        Comment

        Working...
        X