Announcement

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

  • Generate standardized values within subgroups

    I have survey data across several countries and it seems like the responses on ordinal scale have different spreads for different countries.
    Hence, instead of standardizing across the board, I would like to standardize by country.
    Unfortunately, egen x = std(y), by country doesn't work as std can not be used with by.
    Any suggestions?

    Also, I have more than 700 variables...is there any more efficient way than to write an egen for every single variable?

    Thanks in advance for your help.
    Thank you for your help!

    Stata SE/17.0, Windows 10 Enterprise

  • #2
    Why -egen, std()- is not byable is a mystery to me. But it is not a big issue, both -egen, mean- and -egen, sd()- are byable, and standardised value = (value - mean)/standard deviation).

    See here how this is done:

    https://www.statalist.org/forums/for...iple-variables

    Comment


    • #3
      I mean see the code by Nick Cox at the link I posted above.

      As to the issue that you have 700 variable, see the link below on how you can refer to lists of variables without naming them one by one:

      https://www.stata.com/support/faqs/d...ple-variables/

      Comment


      • #4
        Joro's positive suggestions about code are fine in terms of giving what you ask for. But I can't see any good reasons for standardizing here. You're throwing away much of the information in the data thereby.

        Comment


        • #5
          Thank you!

          Nick, I was also thinking of running regressions per country, so standardizing per country could be useful for that.
          Thank you for your help!

          Stata SE/17.0, Windows 10 Enterprise

          Comment


          • #6
            Originally posted by Joro Kolev View Post
            As to the issue that you have 700 variable, see the link below on how you can refer to lists of variables without naming them one by one:

            https://www.stata.com/support/faqs/d...ple-variables/
            But can I generate variables with wildcards? I guess I could always forloop and include the counter in the new variable name...

            Thank you for your help!

            Stata SE/17.0, Windows 10 Enterprise

            Comment

            Working...
            X