Announcement

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

  • How can I multiply category variables by discrete (fractions) variables?

    Hi STATA,


    I want to create a new variable (Age * Education levels). But the problem is that the age variable and education levels variable are categories, for example, the 'Age variable' has five age groups and the 'education levels variable' has five levels of education.
    How can I multiply two category variables by another category variable to create a new variable?

    Also, how can I multiply category variables by discrete (fractions) variables? for example, (age × female’s earnings share of household income(fractions) is not run because the female’s earnings share is a nonintegral variable << STATA commend.

    Also, I have run 2010 and 2016, and 2016 = 1, 2010 = 0. (the year variable is dummy variable)
    When I tried to run these: (never married(dummy variable) × 2016=1), (age(categories) × 2016=1), (age(categories) × level of education (categories)× 2016=1), (age(categories) × level of household income (fractions) × 2016=1), STATA would not run because of too many columns, and rows.

    Could you please assist me?

    Thank you,

  • #2
    Is the purpose of this multiplication making a set of interactions for a regression model?

    Comment


    • #3
      Hm:
      an almost identical query was posted and replied at:
      https://www.statalist.org/forums/for...a-new-variable
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Originally posted by Ken Chui View Post
        Is the purpose of this multiplication making a set of interactions for a regression model?
        Yes, I want to make a set of interactions.

        Comment


        • #5
          Originally posted by Carlo Lazzaro View Post
          Hm:
          an almost identical query was posted and replied at:
          https://www.statalist.org/forums/for...a-new-variable
          You are right, but when I multiply the two categories of variables by year (dummy variable) the STATA couldn't run.
          So, I repost the question with additional details.

          Comment


          • #6
            Originally posted by Hm Saleh View Post

            Yes, I want to make a set of interactions.
            Please do not compute interaction terms by hand, it's very tedious and can create many errors. Use the hashtag (# or ##) to create interactions. See help fvvarlist for the technical document.

            It seems you're trying to create a set of 3-way interactions, it can be done with:

            Code:
            reg y i.year##i.edu##i.age
            The technical document contains all the details as well as many examples. Please study that.

            Comment


            • #7
              Hm:
              [Hm:
              I'd be way better off with letting Stata -fvvarlist- notation do it for you (I assume you're interested in creating a predictor for a regression):
              Code:
              i.age##i.education_levels
              The usual cautionary tale about categorizing a continuous predictor (https://pubmed.ncbi.nlm.nih.gov/16217841) still holds.
              self-quoting is shameless, but it seems that my previous advice (https://www.statalist.org/forums/for...a-new-variable #2) was really similar to the helpful one provided by Ken.
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment


              • #8
                Originally posted by Ken Chui View Post

                Please do not compute interaction terms by hand, it's very tedious and can create many errors. Use the hashtag (# or ##) to create interactions. See help fvvarlist for the technical document.

                It seems you're trying to create a set of 3-way interactions, it can be done with:

                Code:
                reg y i.year##i.edu##i.age
                The technical document contains all the details as well as many examples. Please study that.
                Thank you,

                What about the second and third parts of my question?

                Comment


                • #9
                  Hm:
                  2) -fvvarlist- notation cannot help you out in this respect and you have to multiply the factors by hand, creating anew variable;
                  3) most of the problems related to wave-related dummy creep s up when data are in -wide- (instead of -long-) format.. Is this your case too?;
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment


                  • #10
                    Originally posted by Carlo Lazzaro View Post
                    Hm:
                    2) -fvvarlist- notation cannot help you out in this respect and you have to multiply the factors by hand, creating anew variable;
                    3) most of the problems related to wave-related dummy creep s up when data are in -wide- (instead of -long-) format.. Is this your case too?;
                    Yes, the data are -wide-.

                    Comment


                    • #11
                      Hm:
                      please note that most of the Stata commands need a -long- format to work at their best.
                      I'd recommend you to -reshape- your dataset from -wide- to -long-.
                      Kind regards,
                      Carlo
                      (Stata 19.0)

                      Comment


                      • #12
                        Originally posted by Carlo Lazzaro View Post
                        Hm:
                        2) -fvvarlist- notation cannot help you out in this respect and you have to multiply the factors by hand, creating anew variable;
                        3) most of the problems related to wave-related dummy creep s up when data are in -wide- (instead of -long-) format.. Is this your case too?;
                        What are the effects of reshaping my dataset on my results?

                        Comment


                        • #13
                          Hm:
                          a more efficient (and effective) way of doing your analysis.
                          Kind regards,
                          Carlo
                          (Stata 19.0)

                          Comment

                          Working...
                          X