Announcement

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

  • Problem to gerate a variable

    Hello, I have the following dataset where each observation rapresent an individual. the variable cittad takes value from 1 to 3 and show if a person have Italian citizenship or UE citizenship or extra UE citizenship. Prof1 provide information about the work activities carried out by each person and it range from 1 to 9. Occupazione is the sum of working people for each citizenship group and group of activities, prova_tot_occ is the sum of total worker by each group of citizenship (so the sum of the variable occupazione following the division under cittad) and occ_perc is the percentage of worker which perform the same activities over the total by each group of citizenship.
    What I would like to do is to create a variable of control called verify that for each group of citizenship give me the sum of the occ_perc in order to verify that for each value of the variable cittad the sum of occ_per is = 1.
    Thank you for you attention.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(cittad prof1) float(occupazione prova_tot_occ occ_perc)
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    1 1 7176 227523 .031539667
    end

  • #2
    Enrico:
    do you mean something like:
    Code:
    bysort cittad: egen verify=total( occ_perc)
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Hi Carlo, thank you for your help. I tried your suggestion but the results are not what I would expect. What I'm trying to do is to sum only once the percentage of occupation for each specific sector with respect to the total worker (for each citizenship group) so that at the end the values in the variable verify should be all equal 1. I think that with your command I count each percentage for every person only distinguis by their citizenship. In the data that I posted you can only see one group of citizenship and 1 occupation so it's not very helpful. The variable occ_per is obtained ==> (7176/ 227523). where 7176 is the numebr of worker in the first sector for people with Italian citizenship and 227523 is the total number of worker with italian citizenship. To be sure that all my percentage are corrected I want to sum once the coefficient obtained dividing the number of people working in a specifi sector by the total number of worker and I would expect to obtain 1 .

      Comment


      • #4
        Enrico:
        Code:
        bysort cittad occupazione: egen verify2=total( occ_perc)if _n==1
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          Hi Carlo, I followed your suggestion but it generates only missing values

          Comment


          • #6
            Check out the tag() function of egen.

            Comment


            • #7
              thank you Nick I will try

              Comment


              • #8
                Enrico:
                as far as I can see, when applied to your example, the code generates 99 out of 100 missing values:
                Code:
                . bysort cittad occupazione: egen verify2=total( occ_perc)if _n==1
                (99 missing values generated)
                
                . tab verify2
                
                    verify2 |      Freq.     Percent        Cum.
                ------------+-----------------------------------
                   .0315397 |          1      100.00      100.00
                ------------+-----------------------------------
                      Total |          1      100.00
                
                .
                Kind regards,
                Carlo
                (StataNow 18.5)

                Comment

                Working...
                X