Announcement

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

  • Computation log and fraction

    Hi.
    Thank you in advance for the help.

    I am a total beginner in STATA and
    I would like to calculate the below formula in state and I have the value-added(VA) and employment(EMP) in panel data set to get one of my main variables(Distance) which is the distance from the technology frontier.
    Max means that the highest VA and EMP in the industries. I also know each max VA and max EMP from the dataset

    The point is that when I know each value of VA and EMP, what can be the command to get this Distance in STATA?
    Or will it be better to compute in excel and get the dataset of distance and import it to STATA not computing it in STATA?

    Thank you so much.
    Click image for larger version

Name:	20210826_154405.png
Views:	1
Size:	4.7 KB
ID:	1624983

  • #2
    It's fine to be a beginner, but please do yourself and ourselves a favour by following our request and studying the FAQ Advice https://www.statalist.org/forums/help carefully all the way down through #12 and up to #18. (I want to add to the standard comment that Stata is spelled that way a comment that Excel is spelled that way.)

    Most importantly, you are much more likely to get a good answer quickly if you present example data, or an analogue thereof, and a sample computation showing what you want. You shouldn't expect us to imagine your data or fake an example dataset.

    The trickiest detail in the formula is getting the maximum over a group of ratios, for which the max() function of the egen command in conjunction with by() should help.

    Here is a nonsense analogue of your problem, if I understand it correctly supposing that we care about the ratio price/weight of cars.

    Code:
    . sysuse auto, clear
    (1978 automobile data)
    
    . gen ratio = price/weight
    
    . egen max = max(ratio), by(foreign)
    
    . gen wanted = 1 - log(ratio) / log(max)
    
    . tabstat wanted, by(foreign) s(n min max)
    
    Summary for variables: wanted
    Group variable: foreign (Car origin)
    
     foreign |         N       Min       Max
    ---------+------------------------------
    Domestic |        52         0   .917865
     Foreign |        22         0  .6007873
    ---------+------------------------------
       Total |        74         0   .917865
    ----------------------------------------
    If I guess rightly at your notation, you want to compare values in different countries for the same industry and year. That just means two variables being fed to by() not one.




    Last edited by Nick Cox; 26 Aug 2021, 09:04.

    Comment


    • #3
      No it most certainly is not better to compute in Excel. It is trivial to compute in Stata.

      I will assume your Stata dataset includes the following variables.
      • va (value added)
      • emp (employment)
      • ind (industry)
      • ctry (country)
      • year (t)
      Then what you want seems to be
      Code:
      generate ve = va/emp
      by year ind, sort: egen mve = max(ve)
      generate dist = 1 - log(ve)/log(mve)
      Now some advice I always give to members who identify themselves as new to Stata. I'm sympathetic to you as a new user of Stata - there is quite a lot to absorb.

      When I began using Stata in a serious way, I started, as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. All of these manuals are included as PDFs in the Stata installation and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

      The objective in doing the reading was not so much to master Stata - I'm still far from that goal - as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

      Stata supplies exceptionally good documentation that amply repays the time spent studying it - there's just a lot of it. The path I followed surfaces the things you need to know to get started in a hurry and to work effectively.

      Stata also supples YouTube videos, if that's your thing.
      Last edited by William Lisowski; 26 Aug 2021, 09:03.

      Comment

      Working...
      X