Announcement

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

  • Help on Generating a new variable that combines 2 variables

    Hi,

    I have a dataset which I have imported from Excel into Stata with store and products

    I haven't made any changes to the data so far.

    I need to find a way to create a new variable that uniquely identifies combinations of stores and products. Eg two stores with 2 products each would result in 4 combinations in total and then see how many total combinations there are.

    Please are you able to assist?. When I try, it seems to work but without a new variable where I do tab store product but I need a new variable.

    Thank you!
    Last edited by Mav Mehmood; 08 Oct 2019, 08:07.

  • #2
    Please read the FAQ Advice again. https://www.statalist.org/forums/help#stata

    Requests are specific and explicit: No spreadsheet attachments (we explain why not). Please show Stata datasets through example data. Please show your code. Please explain why it didn't work from your point of view.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Please read the FAQ Advice again. https://www.statalist.org/forums/help#stata

      Requests are specific and explicit: No spreadsheet attachments (we explain why not). Please show Stata datasets through example data. Please show your code. Please explain why it didn't work from your point of view.
      Thanks for your reply. I have updated accordingly.

      Comment


      • #4
        Hey Mavs,
        I was stuck in a very similar way but different variables involved, can you please briefly show how you got your answer, even the commands would be helpful by itself.
        thank you, your help would be really appreciated.

        Comment


        • #5
          the question is #4 is not completely clear to me, but the general answer, esp. if there are "not too many" combinations is to use the -egen- command with the "group" function; ss
          Code:
          help egen

          Comment


          • #6
            Originally posted by ashkan arshad View Post
            Hey Mavs,
            I was stuck in a very similar way but different variables involved, can you please briefly show how you got your answer, even the commands would be helpful by itself.
            thank you, your help would be really appreciated.
            Hi
            I used:

            egen Combine_SP = group (store_id product_id)

            Combine_SP is the name of the new variable I am generating and within the group brackets are the two variables I`m looking for combinations of.

            Hope this helps!

            Comment


            • #7
              Originally posted by Rich Goldstein View Post
              the question is #4 is not completely clear to me, but the general answer, esp. if there are "not too many" combinations is to use the -egen- command with the "group" function; ss
              Code:
              help egen
              Thank you Rich, I have found my answer!

              Comment

              Working...
              X