Announcement

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

  • Problem with catplot

    Hello all,

    I am using the function “Catplot” on Stata and I am having troubles to get out the right figure that I want to present. My variables are: employed (binary), parental education (low, medium, high) and time (0,1). The time variable represents two different cross-sectional waves (2005 and 2011). My aim is to compare the level of employment by different social backgrounds between the two waves. For instance, the number of individuals who have a low parental background and were no employed in 2005 is 16 (28%) compared with 41 (72%) who were employed. On the other hand, the number of individuals who have a low parental background and were not employed in 2011 is 27 (24%) compared with 87 (76%) that were employed.

    What I would like from “Catplot” to produce is a graph that shows people who were not employed in both waves by their different parental background on one side of the graph. For example for one category, I would like to see: Not employed 2005: (28%(16/55)) and Not employed 2011: (24%(27/114)).

    The output that I am getting is including all the frequencies together (16+41+27+87+74+102+201+260+179+201+747+677=2612). These are the frequencies of being employed by different social background in two waves (2x3x2=12 categories). Hence, the graph shows: Not employed 2005: 0.6% (16/2612) and Not employed 2011: 1.6% (41/2612).

    I tried several ways to find the solution by using the option “by”, with no success.

    Here is the function that is producing the latter result:

    catplot time parents_educ employed percent blabel(bar, position(time) format(%9.1f)) title ("Germany") var1opts(gap(0)) recast(bar) bar(1, blcolor(red) bfcolor(red)) asyvars bar(1, color(black))

    Thanks in advance

  • #2
    catplot is a command (not function) from SSC.

    I see no data example here that I can use. The syntax you cite is not legal, but with a comma inserted it might work, There is no graph here either.


    Code:
    catplot time parents_educ employed,  percent blabel(bar, position(time) format(%9.1f)) ///
    title("Germany") var1opts(gap(0)) recast(bar) bar(1, blcolor(red) bfcolor(red)) asyvars bar(1, color(black))
    Sorry, but despite having used catplot I can't follow the question.

    Comment


    • #3
      The two tables show the chances of being employed or not by different social background in 2005 and 2011. The figure that I would like to have in the Catplot is the percentages that are shown (e.g. 28.07%, etc…) in the tables.

      However, as it is shown in the Catplot figure that I uploaded, the values are different than the ones in tables because the percentages that are shown are based on merging the frequencies of both waves (2005 and 2011) together and not each one on its own (as I explained in previous post).


      Click image for larger version

Name:	Catplot graph.png
Views:	1
Size:	141.2 KB
ID:	1508426
      Click image for larger version

Name:	Chances of employment by parental education 2011.png
Views:	1
Size:	103.8 KB
ID:	1508424
      Click image for larger version

Name:	Chances of employment by parental education 2005.png
Views:	1
Size:	103.4 KB
ID:	1508425

      Comment


      • #4
        The forum web page and every new message prompt ask that you read the FAQ before posting, and specifically that you post a data example (which doesn't mean some words about your data) It also explains that screenshots are much less helpful than you hope.

        Here is the key link again:

        https://www.statalist.org/forums/help#stata


        Your catplot from #1 is in terms of
        Code:
          
         time parents_educ employed
        How those variables relate to quite different variables employed05 employed11 in your tabulate results (which use an if restriction which you did not apply to the catplot command according to the code in #1) I do not know. I could start guessing but prefer not to.

        We (I) haven't much hope of understanding your problem unless (a) data (b) code (c) results (here graph and tables) are evident and consistent. My guesses are that you applied the if clause in the tabulate code also in getting the catplot but just did not tell us about it.

        You could do this:

        Code:
        contract time parents_educ employed
        where you should use the if restriction if it applied to your catplot code.

        Then use dataex to show the data. Again the help link above explains.

        Comment


        • #5
          Thanks for your response Nick.

          The variable "employed05" represent the likelihood to be employed or not (0/1) in 2005. The same goes for variable "employed11", but it represents the year 2011. The variable "employed" is a merge between the variables employed05 and employed11. It basically represents the information in 2005 and 2011 but just in 1 variable instead of 2 (see below).

          The if function that apply restrictions is used in all my codes. I did not share it in my initial message to keep things simple, however, it made things more complicated apparently.
          The compact command does not seem to solve the problem. The main issue is that Catplot is merging the frequencies of the years of 2005 and 2011 together and then give me percentages based on the total frequencies of both waves which misrepresents the data. The only solution that I found which works is to run each wave separately as posted in the codes below. I included the graphs of these new codes as well. Do you know of any command that help me merge these graphs nicely (other than graph combine). Or do you know how I can let catplot give me the results of the graphs in one command instead of running them for each wave separately?

          Thanks again for your help and guidance

          Here are the codes that I used to produce the graphs and figures of the previous post:

          tab employed05 parents_educ if country ==5 & targetsample_2==1 & parents_educ !=. & ///
          marital_b !=. & age !=. & health_b !=. & educ !=., col

          tab employed11 parents_educ if country ==5 & targetsample_2==1 & parents_educ !=. & ///
          marital_b !=. & age !=. & health_b !=. & educ !=., col

          catplot time parents_educ employed if targetsample_2 ==1 & country==5 & parents_educ !=. , ///
          percent blabel(bar, position(parents_educ) format(%9.1f)) title ("Germany 2005") var1opts(gap(0)) ///
          recast(bar) bar(1, blcolor(red) bfcolor(red)) asyvars bar(1, color(black))

          Here are the codes that I used to produce the graphs of this post:

          catplot parents_educ employed05 if targetsample_2 ==1 & country==5 & parents_educ !=. , ///
          percent blabel(bar, position(parents_educ) format(%9.1f)) title ("Germany 2005") var1opts(gap(0)) ///
          recast(bar) bar(1, blcolor(red) bfcolor(red)) asyvars bar(1, color(black))

          catplot parents_educ employed11 if targetsample_2 ==1 & country==5 & parents_educ !=. , ///
          percent blabel(bar, position(parents_educ) format(%9.1f)) title ("Germany 2005") var1opts(gap(0)) ///
          recast(bar) bar(1, blcolor(red) bfcolor(red)) asyvars bar(1, color(black))

          Here is the dataex as requested:

          Click image for larger version

Name:	dataex 20 observations.png
Views:	1
Size:	134.1 KB
ID:	1508467
          Click image for larger version

Name:	dataex 20 observations continue.png
Views:	1
Size:	51.5 KB
ID:	1508468
          Click image for larger version

Name:	Catplot_2005.png
Views:	1
Size:	135.2 KB
ID:	1508470 Click image for larger version

Name:	Catplot_2011.png
Views:	1
Size:	133.4 KB
ID:	1508469

          Comment


          • #6
            Please read the link given in #4 again. I cannot copy and paste a screenshot usefully. I will not type in data myself.

            But perhaps you could cut this all out, as I suspect you are not noticing that percent is just a default. You will need to specify how percents are calculated if you don't want the default. This is explained in the help for catplot.

            Comment


            • #7
              If still mystified, study the following sequence:


              Code:
               sysuse auto, clear
               catplot rep78 , percent
               catplot rep78 foreign , percent
               catplot rep78 foreign , percent(foreign)

              Comment


              • #8
                Thanks for the help. You find below the data copied as you have requested. I tried different combinations of the catplot as you have suggested with no success.

                dataex time parents_educ employed employed05 employed11 in 432605/432625

                copy starting from the next line --------------- -------
                [CODE]
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input int time float(parents_educ employed employed05 employed11)
                1 1 1 . 1
                1 1 1 . 1
                1 . 0 . 0
                1 . 0 . 0
                1 1 1 . 1
                1 1 1 . 1
                1 . 1 . 1
                1 . 0 . 0
                1 . 0 . 0
                1 . 0 . 0
                1 . 0 . 0
                1 . 1 . 1
                1 2 1 . 1
                1 1 1 . 1
                1 3 1 . 1
                1 . 0 . 0
                0 2 0 0 .
                0 . 0 0 .
                0 . 1 1 .
                0 2 1 1 .
                0 1 1 1 .
                end
                label values time time
                label def time 0 "2005", modify
                label def time 1 "2011", modify
                label values parents_educ parents_educ2
                label def parents_educ2 1 "Low level", modify
                label def parents_educ2 2 "Medium level", modify
                label def parents_educ2 3 "High level", modify
                label values employed employed1
                label def employed1 0 "Not employed", modify
                label def employed1 1 "Employed", modify
                label values employed05 employed05
                label def employed05 0 Not_employed'", modify"' invalid name
                r(198);

                Comment


                • #9
                  Sorry, but 21 arbitrary observations don't permit addressing your question. I made a precise suggestion in #4. It's still my advice.

                  Comment

                  Working...
                  X