Announcement

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

  • Graph for Cross Sectional Data

    Hello Everyone,
    Please I have 6 cross sectional data (from 2015-2020) where each data is for a particular year.

    All the 6 data have the same variables. One of the variables is income and there is no time/year variable in the data.

    Now I want to plot a graph of Income against Time where the Income (6, 4, 2, 3, 5, 7) will be at the Y-axis whiles the Time (2015-2020) will be at the X-axis.

    Please is there a way to plot such graph for a cross sectional data? I would be grateful for your help, thanks.

  • #2
    I think this means that you have a dataset for each year. If so, no graph such as you want is possible until you combine the datasets using append.

    Comment


    • #3
      Nick Cox, thanks so much for your response. So assuming the 6 datasets are named as 2015, 2016, 2017, 2018, 2019 and 2020, in that case, how would I use the append command to combine all the datasets?

      Comment


      • #4
        Assuming each dataset is named "dataset20xx" for xx=15, 16, ..., 20,

        Code:
        use dataset2015.dta, clear
        forval y=16/19{
            append using dataset20`y'
        }

        Comment


        • #5
          Andrew Musau please I just tried your code now but I got an error message that "file dataset20'y' not found"

          Comment


          • #6
            Andrew Musau 's code assumes that your datasets are called dataset2015 and so on.

            Assuming that is true, you need the punctuation `y' not 'y' as opening and closing single quotes around local macro names are different punctuation characters.

            Comment


            • #7
              Nick Cox and Andrew Musau, thanks so much for helping me to append the dataset. I mistakenly used 'y' instead of `y' but it's ok now after the correction.

              Again after appending the dataset, the total number of observations has increased (it seems it cumulatively added total observations in each dataset) thereby creating missing values in the appended dataset. All efforts to remove those missing values from the appended dataset, all ended up deleting all the observations...

              Please is there any advice to deal with this issue? Thanks.

              Comment


              • #8
                At this point (after appending), you should provide a data example using the dataex command to increase your chances of obtaining helpful responses (see FAQ Advice #12 for details).

                Comment


                • #9
                  Dataset 2015
                  Code:
                  * Example generated by -dataex-. For more info, type help dataex
                  clear
                  input str119 Company_Name str25 Country float Lerner15 double Boone15
                  "RAIFFEISENBANK EBERSCHWANG EGEN"                          "Austria"  .12216572 .3402103098046325
                  "BKS BANK AG"                                              "Austria"  .25856084 .3402103098046325
                  "RAIFFEISENBANK OBERES INNVIERTEL EGEN (MBH)"              "Austria"  .11856291 .3402103098046325
                  "VOLKSBANK SALZBURG EG"                                    "Austria" .035673592 .3402103098046325
                  "SPARKASSE NIEDEROSTERREICH MITTE WEST AKTIENGESELLSCHAFT" "Austria"  .10150906 .3402103098046325
                  "RAIFFEISENBANK ALMTAL EGEN"                               "Austria"   .0900813 .3402103098046325
                  "RAIFFEISENBANK REGION EFERDING EGEN"                      "Austria"   .1461394 .3402103098046325
                  "RAIFFEISENBANK REGION BAD LEONFELDEN EGEN."               "Austria"  .16558547 .3402103098046325
                  "RAIFFEISEN BAUSPARKASSE GMBH"                             "Austria"  .07753494 .3402103098046325
                  "RAIFFEISENLANDESBANK OBEROSTERREICH AG"                   "Austria"  .12537207 .3402103098046325
                  end

                  Comment


                  • #10
                    Dataset 2016

                    Code:
                    * Example generated by -dataex-. For more info, type help dataex
                    clear
                    input str119 Company_Name str25 Country float Lerner16 double Boone16
                    "RAIFFEISENBANK PITTENTAL / BUCKLIGE WELT EGEN"            "Austria"   .0645399 .47842706521225864
                    "RAIFFEISENBANK REGION NEUFELDEN EGEN (MBH)"               "Austria"  .20419525 .47842706521225864
                    "RAIFFEISENBANK TRAISEN-GOELSENTAL EGEN"                   "Austria"  .13742577 .47842706521225864
                    "RAIFFEISENBANK MATTIGTAL EGEN (MBH)"                      "Austria"  .18298206 .47842706521225864
                    "RAIFFEISENBANK TURNAU-ST. LORENZEN EGEN"                  "Austria"  .05201256 .47842706521225864
                    "RAIFFEISENBANK HEILIGENKREUZ-KIRCHBACH -ST. GEORGEN EGEN" "Austria"  .05460331 .47842706521225864
                    "RAIFFEISENBANK ST. STEFAN-JAGERBERG-WOLFSBERG EGEN (MBH)" "Austria" -.13550474 .47842706521225864
                    "RAIFFEISENBANK SCHNEEBERGLAND EGEN"                       "Austria"  .23468895 .47842706521225864
                    "RAIFFEISENBANK PASSAIL EGEN"                              "Austria"  .15757477 .47842706521225864
                    "RAIFFEISENBANK GROSS GERUNGS EGEN"                        "Austria"  .08387008 .47842706521225864
                    end

                    Comment


                    • #11
                      Dataset 2017

                      Code:
                      * Example generated by -dataex-. For more info, type help dataex
                      clear
                      input str119 Company_Name str25 Country float Lerner17 double Boone17
                      "RAIFFEISENKASSE POYSDORF EGEN MBH"                             "Austria"  .09938178 -.08707733723417732
                      "RAIFFEISEN BAUSPARKASSE GMBH"                                  "Austria"  .04462564 -.08707733723417732
                      "DENIZBANK AG"                                                  "Austria"   .3750964 -.08707733723417732
                      "RAIFFEISEN REGIONALBANK MOEDLING EGEN"                         "Austria"  .14215478 -.08707733723417732
                      "RAIFFEISENBANK FRAUENKIRCHEN-MOENCHHOF-PODERSDORF AM SEE EGEN" "Austria" .065117344 -.08707733723417732
                      "RAIFFEISENBANK ST. ANTON AM ARLBERG EGEN"                      "Austria"  .12002766 -.08707733723417732
                      "RAIFFEISENBANK NEUSTIFT IM STUBAI, REG.GEN.M.B.H."             "Austria" .016759828 -.08707733723417732
                      "AUSTRIAN ANADI BANK AG"                                        "Austria"  .07201763 -.08707733723417732
                      "RAIFFEISENBANK REGION FURSTENFELD EGEN"                        "Austria"  .04139705 -.08707733723417732
                      "SPARKASSE DER STADT KITZBUHEL EG"                              "Austria"  .05597178 -.08707733723417732
                      end

                      Comment


                      • #12
                        Andrew Musau Just as you asked me to do, please find the attached sample of my cross sectional dataset above for 2015, 2016 and 2017 and kindly help me to append these dataset sample, thanks.

                        Comment


                        • #13
                          Same code as in #4, except that you need a year variable and some renames.

                          Code:
                          forval y=15/19{
                              use dataset20`y'.dta, clear
                              rename (Lerner?? Boone??) (Lerner Boone)
                              gen year= 20`y'
                              save dataset20`y', replace
                          }
                          use dataset2015.dta, clear
                          forval y=16/19{
                              append using dataset20`y'
                          }
                          Last edited by Andrew Musau; 19 Jan 2023, 08:19.

                          Comment


                          • #14
                            Hello Andrew Musau,
                            Please did your new codes work perfectly for the data samples I sent to you?

                            I just tried your codes now but I get an error message that reads "corresponding oldnames and newnames mismatch"

                            The error message continues by stating that "You specified or implied 1 oldname and 2 newnames"

                            I think the problem is coming from the renaming and so kindly recheck the line of code for renaming the Lerner and Boone.

                            Also double check the code you used for generating the year variable, the issue is I get the value "20" throughout whenever I used that code to generate year variable, thanks.

                            Comment


                            • #15
                              Sorry, this was not tested. The rename command would result in an error. Try

                              Code:
                              forval y=15/19{
                                  use dataset20`y'.dta, clear
                                  rename (Lerner`y' Boone`y') (Lerner Boone)
                                  gen year= 20`y'
                                  save dataset20`y', replace
                              }
                              use dataset2015.dta, clear
                              forval y=16/19{
                                  append using dataset20`y'
                              }

                              Comment

                              Working...
                              X