Announcement

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

  • Creating tables with three corresponding variables

    Hi,
    I'm working with a large dataset of exam results and am interested in exporting a table that summarizes these results. Each exam has an identification number, year and subject name. The year and subject name correspond to the exam ID, but each exam ID has hundreds of seperate observations for each student who took that exam. Each observation also features a unique student grade for that test.

    I havn't been able to find a way to include all this data in one table (so far using table and groups command). Subject name and Year should be directly correlated to Exam ID, so this should only have one suitable value per exam, however I havn't been able to express this group correlation without displaying all the observations in the table. I also encountered difficulties with having the mean column refer to the average of grades within the exam ID and not average of IDs themselves.

    Ideally, the table would look like this:
    Exam ID Subject Name Year N Mean Grade
    123 Math 1997 250 92
    456 English 1999 300 94
    ...
    I would appreciate any help on the best way to approach these issues.
    Many thanks.

  • #2
    Alas, you do not show example data, so I will show you some code that will work for the data set that may or may not resemble what you have. If it doesn't, we will both have wasted our time.

    [code]
    collapse (first) subject_name year (count) N = grade (mean) mean_grade = grade, by(exam_id)
    list, noobs clean
    [code]

    In the future, when asking for help with code, always show example data, and when showing data examples, please use the -dataex- command to do so. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.



    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Hi, thank you. This worked. Next time I will show example data, I am new to stata and statalist.

      Comment

      Working...
      X