Announcement

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

  • Add rows within the group

    Hi,
    I am trying to add individual information in few rows so that to have one row per individual.
    The unique id for each individual can get using the first four columns: district, cluster, household, and person Ser no.
    My file looks like this. ( I am giving an example for three individuals)
    District Cluster household Person Serial no. No of labors Acres output value cost Income
    3 2 1 2 1 1 12000 6400 5600
    3 2 1 2 4 2 11300 3200 8100
    3 2 1 2 7 5 14700 1100 13600
    5 12 3 1 6 2 5000 2000 3000
    5 12 3 1 5 3 7800 4500 3300
    7 4 2 2 4 1 8000 650 7350
    7 4 2 2 3 1 8500 870 7630
    7 4 2 2 2 2 3200 500 2700
    7 4 2 2 1 1 4525 750 3775
    I want to add the information on columns 5,6,7,8,9, and finally, the data file should look like the following table.

    Can anybody kindly help me, please?

    Thank you very much in advance.
    District Cluster household Person Serial no. No of labors Acres own out put value cost Income
    3 2 1 2 12 8 38000 10700 27300
    5 12 3 1 11 5 12800 6500 6300
    7 4 2 2 10 5 24225 2770 21455

  • #2
    Please in future use -dataex- to post the data in code form so that others can immediately input the data.

    Setting up the data. Notice that a couple variable names were changed because the ones you provided had space in it and will not work well:
    Code:
    clear
    input District Cluster     household     Person_Serial_no     No_of_labors Acres output_value cost Income
    3     2     1     2     1     1     12000     6400     5600
    3     2     1     2     4     2     11300     3200     8100
    3     2     1     2     7     5     14700     1100     13600
    5     12     3     1     6     2     5000     2000     3000
    5     12     3     1     5     3     7800     4500     3300
    7     4     2     2     4     1     8000     650     7350
    7     4     2     2     3     1     8500     870     7630
    7     4     2     2     2     2     3200     500     2700
    7     4     2     2     1     1     4525     750     3775
    end
    Here is the code to add the data up:

    Code:
    collapse (sum) No_of_labors Acre output_value cost Income, by(District Cluster household Person_Serial_no)
    Results:
    Code:
         +-----------------------------------------------------------------------------------------+
         | District   Cluster   househ~d   Person~o   No_of_~s   Acres   output~e    cost   Income |
         |-----------------------------------------------------------------------------------------|
      1. |        3         2          1          2         12       8      38000   10700    27300 |
      2. |        5        12          3          1         11       5      12800    6500     6300 |
      3. |        7         4          2          2         10       5      24225    2770    21455 |
         +-----------------------------------------------------------------------------------------+
    Version: Stata 16

    Comment


    • #3
      Thank you soo much.
      Sorry for my mistake.
      Next time I will use -dataex- to post the data.
      Thanx once again

      Comment

      Working...
      X