Announcement

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

  • créer plusieurs variables au même moment

    Good afternoon!
    I want to create a farm income variable that is the product of the production sold and the selling price in FCFA/kg. I need to have several farm income variables for each choice. Is there a way to create them at the same time? Then create a total income variable that is the sum of the variables already created for each choice.
    Thanks

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int hhid double men305_01 long men305_02 int men305_03 double men306_01 int men306_02 double men306_03
    1001 2000    0   0 600   .   .
    1002 4500    0   . 210   .   .
    1003  250    .   . 200   .   .
    1004    0    .   .   .   .   .
    1005 1800    0   0 210   .   .
    1006  500    0   0 600   .   .
    1007 1000    0   0 600   .   .
    1008  960    .   . 225   .   .
    1009    0    0   0   .   .   .
    1010 1000    0   . 225   .   .
    1011 1000    0   0 600   .   .
    1012  200    .   . 250   .   .
    1013 1000    .   . 250   .   .
    1014 3200    0   . 200   .   .
    1015  800    0   0 600   .   .
    1016    0    0   0   .   .   .
    1017  300    .   . 265   .   .
    1018    0    0 100   .   . 250
    1049    .    .   .   .   .   .
    1050    0 3500   .   . 325   .
    end
    label var hhid "group(region departement comrur village numero_du_menage)" 
    label var men305_01 "305 Quantité vendue en kg" 
    label var men305_02 "305 Quantité vendue en kg" 
    label var men305_03 "305 Quantité vendue en kg" 
    label var men306_01 "306 Prix de vente en cours FCFA/kg" 
    label var men306_02 "306 Prix de vente en cours FCFA/kg" 
    label var men306_03 "306 Prix de vente en cours FCFA/kg"

  • #2
    Code:
    isid hhid, sort
    reshape long men305 men306, i(hhid) j(choix) string
    gen revenu = men305*men306
    by hhid: egen revenu_total = total(revenu)
    
    reshape wide men305 men306 revenu, i(hhid) j(choix) string // PROBABLY SKIP THIS!
    Depending on what you will be doing with these results, you are probably better off leaving the data in long layout and skipping the final -reshape wide- command. Most data management and analysis in Stata is easier, or only possible, with long data. But if you know you will be doing the few things that Stata does best in wide layout, the final -reshape wide- command gets you back there.

    Comment


    • #3
      thank you very much Clyde

      Comment

      Working...
      X