Announcement

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

  • Solve non-linear function for every observation in a dataset

    I have a time series dataset with variables n and h. I have a non-linear formula that defines another variable x which is unknown. I would like to calculate the value of x.

    The formula is F.n = (1-e^(-h-x))*(x/(x+h)) + e^(-h-x)*n. And n and h are known, and I want a new column in my dataset with x.

    I have seen many posts explaining the use of nl or mata to solve a given equation, but here I want to solve it for each observation. One way would be a loop over every observation, but I was wondering if this is something more natural in STATA for this problem.
    .
    Here is a sample of my data. The first value for x should be -0.0142 given n=9391.427 , F.n=8018.429, h=0.172263.

    n h
    9391.427 .1722635
    8018.429 .0966985
    7342.858 -.3276868
    10255.28 .2248185
    8228.359 .0086208
    8190.086 -.2185922
    10312.54 .2085913
    8427.848 -.187921
    10249.4 .2352541
    8245.316 .2638937


    Thanks,
Working...
X