Announcement

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

  • How to replicate "logarithmic trendline from excel" in STATA

    I'm in the process of trying to replicate several charts previously done in excel, in STATA. I've been able to find most of what I need to know in the pdf documentation but I'm stumped here. I have a simple excel chart that graphs a line graph of one row of data and then on top of it is a trendline line with the logarithmic option. I've looked and looked and cannot find how to create this trendline, (logarithmic, not just lfit) on STATA.

  • #2
    For various reasons the people who answer most questions here tend to have little or no detailed knowledge of MS Excel.

    You might hit a target of someone fluent in both Excel and Stata (NB) in which case your question will be answered.

    Otherwise please explain what a logarithmic trendline is here: e.g. is it log of y as linear in x, y as linear in log x, etc. for y as response and x as predictor? Either way, I don't think there is a built-in alternative in Stata. You would need to do the appropriate regression, or fit a curve in some way appealing, and then use predict followed by a graph command.

    Please see FAQ Advice all the way to Section 18 if the "NB" here is puzzling.

    Comment


    • #3
      So, I assume you have two variables in your Stata data, one called residential which gives the percent of residential vs commercial whatever, and the other is called year. All you need to do is

      Code:
      gen log_year = log(year)
      regress percent log_year
      predict trend_line, xb
      graph twoway line percent trend_line year

      Comment


      • #4
        It's just an example, as I do appreciate, but it's hard to think of a good reason to use log of calendar year as a predictor.

        Comment

        Working...
        X