Announcement

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

  • Generating new variables

    Hello!
    so in my dataset for people belonging to different groups [a, b, c, d] have scored marks on a test.
    now the cut off for clearing this test is different for each of the groups.
    how can i generate a new variable that records the distance from cutoff for each of these - -

    new variable = Cutoff - total marks


  • #2
    Man:
    without data example from your side, a tentative reply may be:
    Code:
    . sysuse auto.dta
    (1978 automobile data)
    
    . g price_cutoff=2500
    
    . g wanted= price_cutoff-price
    
     . list make foreign price price_cutoff wanted in 1/10
    
         +-------------------------------------------------------+
         | make             foreign    price   price_~f   wanted |
         |-------------------------------------------------------|
      1. | AMC Concord     Domestic    4,099       2500    -1599 |
      2. | AMC Pacer       Domestic    4,749       2500    -2249 |
      3. | AMC Spirit      Domestic    3,799       2500    -1299 |
      4. | Buick Century   Domestic    4,816       2500    -2316 |
      5. | Buick Electra   Domestic    7,827       2500    -5327 |
         |-------------------------------------------------------|
      6. | Buick LeSabre   Domestic    5,788       2500    -3288 |
      7. | Buick Opel      Domestic    4,453       2500    -1953 |
      8. | Buick Regal     Domestic    5,189       2500    -2689 |
      9. | Buick Riviera   Domestic   10,372       2500    -7872 |
     10. | Buick Skylark   Domestic    4,082       2500    -1582 |
         +-------------------------------------------------------+
    
    . 
    
    
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Got it,
      thanks so much Carlo!

      Comment

      Working...
      X