Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6471619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:14:42+00:00 2026-05-25T06:14:42+00:00

I am not a statistics guy but have to deal with quite some data.

  • 0

I am not a statistics guy but have to deal with quite some data. In most cases these data sets come from an online survey; hence I do have a MySQL database and know how to get some results out of that.

However, now I got a Stata file and I am required to do some analysis. In MySQL I’d know how to do that, but I am stuck in Stata and ask for your help.

I have a not too small table (roughly 50k rows) containing following columns (there are more cols but these are the ones I have to work with):

id – Object ID, unique values

name – Name of object, string value

class – Class of object, integer range 1 – 6

origin – Origin of object, integer range 1 – 2

Within the 50k rows there are only about 7k different names. In Stata I can retrieve all names with list name and could even restrict it to a single class with list name if class == 2.

Now I want a list of all different names along with a count of objects having that name and have the list sorted by count.
In MySQL I’d query SELECT name, COUNT(*) AS cnt FROM objects GROUP BY name ORDER BY cnt DESC. But how would that be done in Stata?

Next steps would be to get such lists for each class or for both origins, i.e. SELECT name, COUNT(*) AS cnt FROM objects WHERE class = 2 GROUP BY name ORDER BY cnt DESC, is that possible with Stata, too?

ps: I don’t know if stackoverflow is the right place as Stata is not really a programming language, is it? But I found some Stata-related questions here; that’s why I posted it here. If there’s a better place to do so, please point me to the right place.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:14:43+00:00Added an answer on May 25, 2026 at 6:14 am

    Keep in mind that Stata only works with rectangular tables of fixed length, so you can only add columns that span the whole 50k rows. Within this setup, this is what you can do.

    For the first problem (the list of names and frequencies), you can

       collapse (count) freq = name, by(class)
       sort class freq name
       list class name freq, sepby(class)
    

    Note that collapse will delete the existing data and replace with the summary. (Usually, I hate this command for this aspect of data management, but it should work here.) If you don’t want this to happen, here’s a more sophisticated trick:

       bysort class name : generate long freq = _N
       bysort class name : generate byte first = (_n==1)
       sort class freq name
       list class name freq if first, sepby(class)
    

    (Explanation: _N is the number of observations in by-group, and _n is the number of the current observation within the by-group.)

    You can then subset this to the class of interest with if class==#, as you already know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two sets of statistics generated from processing. The data from the processing
I have been doing some statistics work with Stata recently and not enjoying it
The developer console provides basic install statistics but does not provide any historical data
I am having some issues with Android market statistics as they have not been
I am not sure if this is a programming or statistics question, but I
I have a program that downloads basic historical stock data from yahoo and puts
I have some statistics I need to report on a monthly basis. I need
I have been looking for some good statistics package for Common Lisp, that should
I have statistics for every user in our system. These statistics need to be
I have a view that averages some statistics by averaging past rows relative to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.