Announcement

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

  • censored data tobit regression

    I am trying to complete a tobit regression with censored data. This is because i am looking at expenditure shares for wine as the dependent variable however some households report zero consumption of wine therefore i want to censor the data at zero for the dependent variable (expshare_wine_on) my independent variables include: the log price of wine, log income, the gender (sexhrp), the year (2007-2009), the socio-group (4 groups) and the government region (4 groups). I have created dummy variables for the gender, year, socio group and government region (shown as the _I variables)

    I have never used the tobit regression before and i have tried inputting the following command into stata however it says "nothing found where name expected", where am i going wrong?

    tobit expshare_wine_on [l_p_wine_on log income _Isexhrp_2 _Iyear_2008 _Iyear_2009 _Isocio_gro_2 _Isocio_gro_3 _Igor_2 _Igor_3] , ll(0)

    Here is a stataex of my data:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(expshare_wine_on logincome l_p_wine_on) byte(_Isexhrp_2 _Iyear_2008 _Iyear_2009 _Isocio_gro_2 _Isocio_gro_3 _Igor_2 _Igor_3)
              0  6.422159 . 0 0 0 0 0 0 1
              0   6.40044 . 0 0 0 0 0 0 1
     .005604915  7.459103 . 1 0 0 0 0 1 0
              0  6.775366 . 0 0 0 0 0 0 1
              0  7.113805 . 1 0 0 0 0 0 1
              0  6.569739 . 0 0 0 0 0 1 0
              0  5.533982 . 0 0 0 0 0 0 0
              0  7.579028 . 0 0 0 0 0 0 0
              0  6.593606 . 1 0 0 0 1 0 1
              0  5.272487 . 0 0 0 0 0 1 0
              0  6.609026 . 0 0 0 0 0 0 1
              0  5.938198 . 1 0 0 0 1 1 0
              0  7.337308 . 0 0 0 1 0 0 1
              0  7.146323 . 0 0 0 1 0 0 0
     .006608747  5.750647 . 0 0 0 0 0 0 0
              0  7.203275 . 0 0 0 0 0 0 0
              0  6.494836 . 1 0 0 0 1 0 0
     .013427625  6.484792 . 0 0 0 0 0 1 0
              0  6.522772 . 1 0 0 0 0 0 0
              0  6.285625 . 0 0 0 0 0 0 0
              0  5.278839 . 1 0 0 0 0 1 0
              0  5.735572 . 0 0 0 0 0 0 0
              0  6.332039 . 0 0 0 0 0 0 1
              0  6.243429 . 1 0 0 0 0 0 1
      .04080451  7.020963 . 0 0 0 0 0 0 1
              0  6.001791 . 0 0 0 0 0 0 0
              0  4.970105 . 1 0 0 0 0 1 0
      .05318476   6.24026 . 1 0 0 0 0 0 1
     .004725324  6.525675 . 1 0 0 0 0 0 0
              0  5.715316 . 1 0 0 0 0 0 1
              0  6.292069 . 0 0 0 0 0 1 0
    .0021395173  7.579028 . 0 0 0 1 0 0 1
              0  5.805894 . 0 0 0 0 0 0 0
              0  6.336164 . 1 0 0 0 0 0 0
     .005811018   6.59858 . 0 0 0 0 0 1 0
      .01420468  7.579028 . 0 0 0 1 0 0 1
              0  5.272558 . 0 0 0 0 0 1 0
              0  5.287823 . 1 0 0 0 0 0 0
              0  6.228738 . 0 0 0 0 0 0 0
              0  6.229595 . 0 0 0 0 1 0 1
              0  6.007731 . 1 0 0 0 0 0 0
              0  5.877369 . 0 0 0 0 0 0 0
    .0041208593   6.54662 . 1 0 0 1 0 0 1
       .0124029  5.966916 . 1 0 0 0 0 0 1
              0  6.911763 . 0 0 0 0 1 0 1
              0  6.145001 . 0 0 0 0 1 0 1
              0  7.579028 . 0 0 0 0 0 0 1
     .006529902  6.862258 . 0 0 0 0 0 0 0
              0  5.800377 . 1 0 0 0 0 0 1
              0  6.824134 . 0 0 0 0 0 0 0
              0  6.789703 . 1 0 0 0 0 0 0
              0  6.928361 . 1 0 0 1 0 0 1
              0  6.399566 . 0 0 0 0 0 0 0
              0  6.500343 . 0 0 0 0 1 1 0
              0 4.4601445 . 1 0 0 0 0 1 0
              0  6.617764 . 0 0 0 0 1 0 1
              0  5.679811 . 0 0 0 0 0 1 0
              0  6.867948 . 0 0 0 0 0 0 0
      .05028144  6.313678 . 1 0 0 0 1 0 0
              0  6.596409 . 1 0 0 0 0 0 0
     .017830186  6.492455 . 0 0 0 0 0 0 0
              0  6.114235 . 0 0 0 0 1 0 0
              0  6.092607 . 0 0 0 0 0 1 0
              0  6.205401 . 0 0 0 0 1 0 0
              0  6.580847 . 0 0 0 0 1 1 0
              0  4.314417 . 0 0 0 0 0 0 0
     .016797012  6.386812 . 0 0 0 0 0 0 0
              0  5.972129 . 0 0 0 0 1 0 1
              0  6.175955 . 1 0 0 0 0 0 1
              0  5.530817 . 1 0 0 0 0 0 1
              0   6.25011 . 1 0 0 0 0 0 0
              0  5.958502 . 0 0 0 0 0 0 1
      .02511486  7.579028 . 0 0 0 0 0 0 0
              0  6.898997 . 1 0 0 0 0 1 0
              0  5.885359 . 1 0 0 0 0 1 0
              0  6.709394 . 0 0 0 0 0 0 0
              0  5.036965 . 1 0 0 0 0 0 1
              0  6.327079 . 1 0 0 0 0 0 0
              0  4.998036 . 0 0 0 0 0 0 1
              0  6.697083 . 0 0 0 0 1 0 0
              0  5.011914 . 1 0 0 0 0 0 1
              0  6.158079 . 1 0 0 0 0 0 1
              0  7.176102 . 0 0 0 0 0 0 0
              0  5.896472 . 1 0 0 0 0 0 1
              0  6.951744 . 0 0 0 1 0 0 1
              0  5.197281 . 0 0 0 0 1 1 0
              0  7.545757 . 0 0 0 1 0 0 1
              0  5.673536 . 1 0 0 0 0 0 0
      .01174157  6.977282 . 1 0 0 0 0 0 0
              0  6.517243 . 0 0 0 0 0 0 0
     .007315162  6.570533 . 0 0 0 0 0 1 0
              0  6.649363 . 1 0 0 0 0 1 0
              0  6.787118 . 1 0 0 0 0 1 0
              0  7.313854 . 0 0 0 0 0 0 0
              0  6.104423 . 1 0 0 0 0 0 1
              0   5.72316 . 1 0 0 0 0 0 0
              0  5.897319 . 1 0 0 0 1 0 1
              0  5.243925 . 1 0 0 0 0 0 1
    .0021459134  7.579028 . 0 0 0 1 0 0 0
              0  6.524854 . 0 0 0 0 0 1 0
    end
    Thank you for any help in advance

  • #2
    Anya:
    what if you run:
    Code:
    tobit expshare_wine_on l_p_wine_on logincome _Isexhrp_2 _Iyear_2008 _Iyear_2009 _Isocio_gro_2 _Isocio_gro_3 _Igor_2 _Igor_3, ll(0)
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Sorry that was a typo, it is logincome which i have been running however when i type that into stata it comes back as "no observations".

      Comment


      • #4
        Anya:
        what you got from Stata makes perfect sense, since -l_p_wine_on- has only missing values, as you can easily test yourself:
        Code:
        . codebook l_p_wine_on
        
        ---------------------------------------------------------------------------------------------------------------------
        l_p_wine_on                                                                                               (unlabeled)
        ---------------------------------------------------------------------------------------------------------------------
        
                          type:  numeric (float)
        
                         range:  [.,.]                        units:  .
                 unique values:  0                        missing .:  100/100
        
                    tabulation:  Freq.  Value
                                   100  .
        
        .
        As you may already aware of, Stata omits by default observations with misssing values in any variable. If, as in your case, a variable is missing across all the observations, you will unavoidably end up with a -no observation- error.
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          Thank you so much Carlo for identifying the problem. I don't know why it has missing values as i did previously put in the values.
          I now want to put in the values using the data editor and i have attached a screenshot. However how do i put in the same value for several observations without typing it out each time as between row 1 and 1200 the price remains constant at 2.06

          Thanks
          Click image for larger version

Name:	Screenshot 2019-04-28 at 12.42.47.png
Views:	1
Size:	152.9 KB
ID:	1495499

          Comment


          • #6
            Anya:
            Code:
            replace p_wine_on=2.06 if p_wine_on==.
            As a (seemingly) pedantic advice (which is however based on sound reasons that you can read in the FAQ), please note that attaching screenshots is not considered a good habit on this forum. Thanks.
            Kind regards,
            Carlo
            (StataNow 18.5)

            Comment


            • #7
              Sorry my mistake for the screenshot. Thank you for the code, i have noticed using the data editor that my price data has inserted itself below the rest of the cross sectional data. So that each is row is empty where the prices should be and the prices are on their own rows. If i use the "replace" command will this remove them where they were originally as having the prices separately to the other cross sectional data has doubled my observations however i want to reduce my observations back to the correct number

              Hope that makes sense
              Thank you

              Comment


              • #8
                Anya:
                if I got your query right, the following toy-example can give you some suggestions:
                Code:
                . set obs 10
                number of observations (_N) was 0, now 10
                
                .
                . g id=_n in 1/5
                (5 missing values generated)
                
                .
                . g A=1
                
                .
                . list
                
                     +--------+
                     | id   A |
                     |--------|
                  1. |  1   1 |
                  2. |  2   1 |
                  3. |  3   1 |
                  4. |  4   1 |
                  5. |  5   1 |
                     |--------|
                  6. |  .   1 |
                  7. |  .   1 |
                  8. |  .   1 |
                  9. |  .   1 |
                 10. |  .   1 |
                     +--------+
                
                .
                . drop if id==.
                (5 observations deleted)
                
                .
                . list
                
                     +--------+
                     | id   A |
                     |--------|
                  1. |  1   1 |
                  2. |  2   1 |
                  3. |  3   1 |
                  4. |  4   1 |
                  5. |  5   1 |
                     +--------+
                
                .
                Kind regards,
                Carlo
                (StataNow 18.5)

                Comment


                • #9
                  Thanks Carlo, that code worked

                  Comment

                  Working...
                  X