Announcement

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

  • Loop

    Hello fellow Stata users,

    I have a question regarding the forvalues loop, this is the first time I want to use it. I have a variable called "Distmetro" which is the distance to the metro.
    The question that needs to be answered is this:
    "Now we want to estimate the marginal effect of distmetro for the non-parametric and semi-parametric models. Repeat this approximation for various distances and do this for both the non-parametric and semiparametric estimation. For example, 100m, 200m, 400m, 600m, 1000m, 2000m, 3000m. Tip: It may be useful to code a loop."

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double distmetro
     458.2579040527344
    1916.4649658203125
     1843.400146484375
    2018.2406005859375
     2277.740478515625
        370.2373046875
    1131.3287353515625
         1156.41015625
     309.6813049316406
     564.4126586914063
       1433.2822265625
     1289.849365234375
     1385.840087890625
      1223.51025390625
    1727.3624267578125
    1923.1534423828125
     2043.496337890625
     1678.600830078125
      1565.65380859375
    1584.6746826171875
    1998.6033935546875
     371.5183410644531
    505.54559326171875
     640.9423217773438
     640.9423217773438
    1321.6929931640625
        1045.044921875
     2019.236083984375
     398.2286376953125
     1255.669189453125
     2103.856201171875
     2463.675537109375
     2357.287353515625
     1195.438720703125
    1594.8824462890625
    119.31536102294922
     403.8852233886719
      1725.53662109375
    1744.9683837890625
     1658.052001953125
     1793.210205078125
     712.0525512695313
    1101.7047119140625
     2019.236083984375
     1721.634521484375
    1321.6605224609375
     911.4725341796875
     832.2876586914063
     564.3883666992188
         619.013671875
    277.81719970703125
     394.5236511230469
      564.499267578125
    1278.1434326171875
    1095.9532470703125
     2109.886962890625
      2057.14208984375
       2064.8876953125
      2503.75927734375
      2194.31689453125
          1194.3828125
      3533.34326171875
    362.93072509765625
     535.9008178710938
      1396.98291015625
    312.04754638671875
     497.8690185546875
     969.5977783203125
     1773.638916015625
    1527.2176513671875
      2009.80126953125
    1769.6451416015625
     2100.688232421875
     1947.579833984375
     1914.360595703125
        2083.279296875
       2499.2138671875
     2436.013427734375
     972.3533325195313
    1372.7518310546875
     176.5154266357422
     976.3056030273438
     1399.171630859375
       1081.5009765625
           1542.015625
    1053.1322021484375
    1044.7945556640625
     465.8895568847656
     993.1671752929688
     993.1671752929688
        1260.998046875
    1839.2691650390625
         1806.71484375
    1786.1949462890625
     2439.008544921875
      2524.68505859375
      2593.27587890625
     753.3658447265625
     690.3713989257813
    1591.0655517578125
    end
    I appreciate any help how someone could help me produce the forvalues function!
    Last edited by Adam Klaas; 24 Feb 2023, 14:15.

  • #2
    Please see #4 of https://www.statalist.org/forums/help#adviceextras for our policy on homework.

    Comment


    • #3
      The help for foreach does a great job at explaining the details behind this.

      Comment

      Working...
      X