Announcement

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

  • Generating a mean variable for a group of variables with same prefix

    (Stata version 13)

    I have a group of monthy variables for 2012 that have the same prefix in their name: fesc_info_2012. I have fesc_info_2012_1, fesc_info_2012_2, ... , fesc_info_2012_12. I want to create a variable named fesc_info for the mean of these variables. I tried

    egen fesc_info = mean(fesc_info2012*)

    and

    egen fesc_info = mean(fesc_info2012_*)

    but in both cases I receive the same error message:

    fesc_info2012* invalid name
    r(198);

    Can anyone point out what I'm doing wrong?

    Regards,

    Maria

  • #2
    umm... simple typo, and mis-reading of egen's options.. You want rmean, and you are missing a "_"

    egen fesc_info = rmean(fesc_info_2012_*)

    *not*

    egen fesc_info = mean(fesc_info2012_*)

    Comment


    • #3
      I thought it worked as egen newvar=mean(varlist). "summarize" works but I wanted to create a new variable in a more direct way... Thank you for the suggestion anyways.

      Comment


      • #4
        Thank you, Ben! My mistake. rmean works.

        Comment


        • #5
          I deleted the post since it seems like Ben Earnhart read your intention better. Note that -egen rmean()- is undocumented in Stata 13; it works currently as rowmean().

          Comment


          • #6
            Thank you for the pointer, Aspen. I was looking for rmean in the Stata 13 manual.

            Comment


            • #7
              Your variable names are fesc_info_2012_*, but in your -egen- statement you referred to them as fesc_info2012*, omitting the underscore between info and 2012.

              I just noticed this is a duplicate post, and it has already been adequately dealt with by others.
              Last edited by Clyde Schechter; 15 Sep 2014, 21:12. Reason: Just realized this was a duplicate post.

              Comment


              • #8
                Interesting. I will update my mind and notes to use the proper syntax for the future, For now, -rmean- does the same as -rowmean- but come Stata 14, might not only be deprecated, but gone. Huh. Improvement? I dunno, depends on the command and if they altered other behaviors. Thanks for your correction/clarification, Aspen.
                Last edited by ben earnhart; 15 Sep 2014, 22:10.

                Comment


                • #9
                  Ben, you are just very old-fashioned. http://www.stata.com/statalist/archi.../msg00087.html

                  rmean seems to have survived a while, but not all functions are so lucky.
                  -------------------------------------------
                  Richard Williams, Notre Dame Dept of Sociology
                  StataNow Version: 19.5 MP (2 processor)

                  EMAIL: [email protected]
                  WWW: https://www3.nd.edu/~rwilliam

                  Comment


                  • #10
                    Hmmm Richard Williams calling me "very old-fashioned." I'll sleep on that, and probably come to the conclusion that Richard Williams is "cutting edge."

                    Comment


                    • #11
                      Ben, given that you use rmean, I'm guessing you'll start saying STATA next. ;-)

                      At least you are not using xi: It drives me nuts when people do that.

                      It also drives me nuts when some old name for a function that I have long used suddenly stops working. I would just leave such things undocumented but working. It would be really confusing if a function name that was made outdated in Stata 9 suddenly came back with a totally different meaning in Stata 13.
                      -------------------------------------------
                      Richard Williams, Notre Dame Dept of Sociology
                      StataNow Version: 19.5 MP (2 processor)

                      EMAIL: [email protected]
                      WWW: https://www3.nd.edu/~rwilliam

                      Comment


                      • #12
                        Richard: I find it difficult to recall any official Stata function that just stopped working. In the case of -egen-, the change referred to here is that several official -egen- functions were renamed in Stata 9 -- thanks largely to Svend Juul, who explained that StataCorp's naming was a bit of a mess. But the old names continue to work. Typically, the old name defines a program which is a wrapper for the new program.

                        Comment


                        • #13
                          Here is an example:

                          Code:
                          . clear all
                          
                          . set obs 100
                          obs was 0, now 100
                          
                          . 
                          . gen x = norm(1)
                          unknown function norm()
                          r(133);
                          
                          . 
                          . version 9: gen x = norm(1)
                          norm got renamed to normal in Stata 9. My recall is that it and other renamed functions continued to work for a while but stopped working a version or so later. Apparently egen functions renamed in Stata 9 lived on albeit undocumented, but this was not true for gen functions.
                          -------------------------------------------
                          Richard Williams, Notre Dame Dept of Sociology
                          StataNow Version: 19.5 MP (2 processor)

                          EMAIL: [email protected]
                          WWW: https://www3.nd.edu/~rwilliam

                          Comment


                          • #14
                            Functions other than those in egen are just functions; they are not defined by the possibility that you might use them in generate.

                            The error message here is reasonable here. The function is available under version control, and that's documented. StataCorp have a mechanism to correct a poor decision, here on a function name.

                            Comment


                            • #15
                              I'd still like the old names to remain alive even if undocumented. I just remember a lot of confusion back when Stata 10 or 11 came out and all these functions I was used to using suddenly were illegal. If Ben gets to keep using rmean I say I should get to keep using norm. ;-)

                              A related point, which I have made before, is that huge portions of Stata are undocumented, i.e. all the commands and code that only work under version control. When looking at old code, it can be hard to figure out what the program is doing. I keep Stata 7 through 13 on my computer mostly so I can check old help files.
                              -------------------------------------------
                              Richard Williams, Notre Dame Dept of Sociology
                              StataNow Version: 19.5 MP (2 processor)

                              EMAIL: [email protected]
                              WWW: https://www3.nd.edu/~rwilliam

                              Comment

                              Working...
                              X