Announcement

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

  • Generating Percentage Variables

    Hi,
    I’m new to stata and am having trouble creating percentage variable (out of 100) for the percentage of population (in a particular context) eligible for Medicare . I have a variable (A)for the number of eligible people and another variable for sum of race and ethnicity. Which of the following two syntax should be used to create the new percentage variable (C) out of 100:
    1. generate variable (C)== variable A/ variable B *100
    2. generate variable (C)==100 variable A/((variable B)*100)
    3. generate variable (C)==100 (variable A/variable B) *100

    Or if I should use a totally different variable ? I’m not good in math as well:-)

    Best,

    Arif
    Last edited by Arif Mujaddedi; 03 Mar 2019, 06:40.

  • #2
    Welcome to Statalist. It is a recommended practice here to post your data using the dataex (from SSC). See the following example dataset and the code to generate percentages
    Code:
    clear
    input float(A B)
    348 398
    266 316
    136 186
     28  78
    868 918
    350 400
     71 121
    323 373
    555 605
    875 925
    end
    
    * Find percentage
    gen C = 100 * A / B
    
    
    . list
    
         +----------------------+
         |   A     B          C |
         |----------------------|
      1. | 348   398   87.43719 |
      2. | 266   316   84.17722 |
      3. | 136   186   73.11828 |
      4. |  28    78   35.89743 |
      5. | 868   918   94.55338 |
         |----------------------|
      6. | 350   400       87.5 |
      7. |  71   121   58.67768 |
      8. | 323   373   86.59518 |
      9. | 555   605   91.73553 |
     10. | 875   925    94.5946 |
         +----------------------+
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment

    Working...
    X