Announcement

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

  • Multiply variables

    Hi all,

    I need to multiply one variable with another. I know this can be done with: gen NBxPL= NB * PL
    However, I have to do this with many variables. NB needs to be mulitplied with PL1, PL2, PL3.... (and so on) until PL100.

    Is there an option to do this at once?

    Thanks in advance for your help!

  • #2
    You mean this?

    Code:
    gen double NBxPL = NB 
    
    quietly forval j = 1/100 { 
          replace NBxPL = NPxPL * PL`j' 
    }

    Comment


    • #3
      Or did you mean to make 100 separate products, like this?
      Code:
      quietly forval j = 1/100 {
            generate NBxPL`j' = NB  * PL`j'
      }
      Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post, looking especially at sections 9-12 on how to best pose your question. It would have been helpful to post a small hand-made example, with just a few variables and observations, showing the data before the process and how you expect it to look after the process.
      Last edited by William Lisowski; 16 Jun 2016, 13:06.

      Comment


      • #4
        I finally need all variables NB_PL1, NB_PL2...., till NB_PL100:
        NB_PL1=NB*PL1 (Variable NB multiplied with PL1)
        NB_PL2=NB*PL2
        NB_PL3=NB*PL3
        ...... and so on until:
        NB_PL100=NB*PL100

        Comment

        Working...
        X