Announcement

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

  • Question regarding variable collapse

    Hey StataList,

    I'm working on a replication study, but the authors couldn't share their do-file - so maybe you could help (would be much appreciated).

    My data is from the European Values Study from 2008*, and my question is, how do I collapse a variable to get a mean score for, for instance, Austria and v223?

    Data can be found here: https://search.gesis.org/research_da...0.4232/1.13841

    Thank you! 🤠

  • #2
    To download the data the website requires a membership; it'd be better if you can use dataex to provide some sample data.

    Anyhow, this code is untested. Assuming "Austria" is one of the levels inside a variable called "country":

    Code:
    collapse (mean) v223, by(country)

    Comment


    • #3
      Hey Ken, thanks! Not sure how to use the dataex, but here is a picture of "my situation", haha.
      Click image for larger version

Name:	STATAAustria.png
Views:	1
Size:	567.2 KB
ID:	1732057

      Comment


      • #4
        You'll have to check the coding scheme of V224. It seems to be an ordinal variable with some "don't know" mixed in it.

        And use help dataex to learn how to operate dataex. And allow me suggest the code here for you:

        Code:
        dataex country V224, count(80)
        My advice is please learn this command, kind of essential in order to have your questions answered well and quickly here.

        Comment


        • #5
          Thank you. Here is a sample from the dataset.
          Code:
          clear
          input int country byte v223
          40 2
          40 2
          40 1
          40 2
          40 2
          40 2
          40 .
          40 3
          40 1
          40 2
          40 1
          40 1
          40 3
          40 4
          40 2
          40 2
          40 2
          40 3
          40 4
          40 3
          40 4
          40 2
          40 3
          40 2
          40 2
          40 3
          40 2
          40 3
          40 2
          40 3
          40 3
          40 3
          40 2
          40 2
          40 3
          40 4
          40 3
          40 3
          40 2
          40 2
          40 2
          40 4
          40 3
          40 3
          40 2
          40 1
          40 2
          40 1
          40 2
          40 3
          40 4
          40 3
          40 2
          40 3
          40 3
          40 3
          40 2
          40 2
          40 2
          40 3
          40 2
          40 2
          40 3
          40 2
          40 2
          40 2
          40 2
          40 2
          40 3
          40 2
          40 2
          40 3
          40 4
          40 3
          40 3
          40 4
          40 4
          40 3
          40 3
          40 3
          end
          label values country COUNTRY
          label def COUNTRY 40 "Austria", modify
          label values v223 V223
          label def V223 1 "very satisfied", modify
          label def V223 2 "rather satisfied", modify
          label def V223 3 "not very satisfied", modify
          label def V223 4 "not at all satisfied", modify

          Comment


          • #6
            Is there a reason you need to collapse? Almost all that data is categorical. And egen or tabstat will get you the means without collapsing. You can't do much with the collapse data since there's are not that many countries in the sample.

            v122 is a dummy using 0/1, so the mean works.

            Code:
            tabstat v122 if v122>=0 , by(country)

            Comment


            • #7
              Thank you for your comment - much appreciated; after reflecting on it, you're absolutely right.

              Now, I'm just speculating on merging the dataset with another having only one observation per country (for instance, GDP per capita per country).

              Comment


              • #8
                joinby will match that other data to all occurrences by country, if that's what you're after.

                Comment

                Working...
                X